PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 12th, 2004, 05:11 PM
Think Pink Think Pink is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 4 Think Pink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
desperatly need help

hello. I'm trying for many days now to make a dropdown that has an onchange event.
I have the following drpdown :

PHP Code:
<form name="country" action="<? $PHP_SELF; ?>" method="post">
<
select name="chooseCountry" onChange="submitpage()">
<
option value='0'>Choose country</option>
<?
$querydrop "select * from countryes";
$result mysql_query($querydrop);
 
while(
$row mysql_fetch_array($result)) 

if(
$row['id']==$chooseCountry

print 
"<option value=\"".$row['id']." selected\">".$row['country_name']."</option>"

else 

print 
"<option value=\"".$row['id']."\">".$row['country_name']."</option>"


 
?>
</select>
</form> 


OK. When I select a country, the form is submited, the page reloaded and and the selected option is the first in the list.

I want that after the form is submited and the page reloaded, the selected country to be the one I choosed before.

Pls help
Thx a lot

Reply With Quote
  #2  
Old August 12th, 2004, 05:46 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information. Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 992 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2Folding Points: 734494 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 13 h 37 m 16 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Ok, code is mostly ok, but you made a few mistakes, which probably comeup because you're assuming an old server-config.
Your code assumes register_globals is on, in other words, you access all server and POST variables by their direct name, instead of fetching them from their respective arrays, however, few servers allow that nowadays, as it is a serious security flaw, so you should instead get them from the global arrays.
The variables you try to use are:
$PHP_SELF
$chooseCountry
they should be:
$_SERVER['PHP_SELF'] (you also forgot to echo this one)
$_POST['chooseCountry']

next, there are a few minor flaws in your HTML.
to make an <option> selected, the proper code is:
<option value="value" selected="selected">
instead of
<option value="value selected">

Finally, unless you've defined a javascript function submitpage() yourself, the proper code would be submit(this), to submit the form on the onchange.

The correct code would then read (tested this):
PHP Code:
 ?>
<form name="country" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="chooseCountry" onChange="submit(this)">
<option value='0'>Choose country</option>
<?
$querydrop 
"select * from countryes";
$result mysql_query($querydrop);
 
while(
$row mysql_fetch_array($result)) 

    if(
$row['id']==$_POST['chooseCountry']) 
    { 
        print 
"<option value=\"".$row['id']."\" selected=\"selected\">".$row['country_name']."</option>\n"
    } 
    else 
    { 
        print 
"<option value=\"".$row['id']."\">".$row['country_name']."</option>\n"
    } 

 
?>
</select>
</form> 


Hope this helps.

PS: the correct plural of country is countries, not countryes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > desperatly need help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway