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
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,030 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: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1972097 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 1 Week 9 h 8 m 43 sec
Reputation Power: 7
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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek