943,528 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 925
  • PHP RSS
Jul 2nd, 2009
0

Problem with PhP MySql Ajax dropdown code

Expand Post »
HI, I am using Roshan's Ajax dropdown code for my two ajax dropdown menus.

All is working fine, but when I want to use $_POST in the submitted form in FireFox, its not working...??? Its working fine in IE.

Can anybody please help me with this problem?

The Form where the dropdown is:
PHP Syntax (Toggle Plain Text)
  1. <!-- Province goes here -->
  2. <tr>
  3. <td>-</td><td>-</td><td>-</td><td>-</td><td>Province</td><td>
  4. <select name="province" onChange="getCity('../dir/townsrc.php?province='+this.value)">
  5. <option value="">Select Province</option>
  6. <option value="1">KwaZulu-Natal</option>
  7. <option value="2">Western Cape</option>
  8. <option value="3">Eastern Cape</option>
  9. <option value="4">Free State</option>
  10. <option value="5">Gauteng</option>
  11. <option value="6">Limpopo</option>
  12. <option value="7">Mpumalanga</option>
  13. <option value="8">North West</option>
  14. <option value="9">Northern Cape</option>
  15. </select>
  16. </td>
  17. </tr>
  18. <!-- Province ends here -->
  19. <!-- Town goes here -->
  20. <tr>
  21. <td>-</td><td>-</td><td>-</td><td>-</td><td>Town</td><td>
  22. <div id="citydiv"><select name="city">
  23. <option>Select Town</option>
  24. </select>
  25. </div>
  26.  
  27. </td>
  28. </tr>
  29. <!-- Town ends here -->

The townsrc.php:
PHP Syntax (Toggle Plain Text)
  1. <? $country=intval($_GET['province']);
  2.  
  3. $query=("SELECT * FROM search_town
  4. WHERE provId=$country
  5. ORDER BY townLabel ASC");
  6. $result=mysql_query($query);
  7.  
  8. ?>
  9. <select name="city">
  10. <option>Select Town</option>
  11. <? while($row=mysql_fetch_array($result)) { ?>
  12. <option value><?=$row['townLabel']?></option>
  13. <? } ?>
  14. </select>

The submit for:
PHP Syntax (Toggle Plain Text)
  1. $province = trim($_POST['province']);
  2. $city = trim($_POST['city']);

In IE $province and $city gets posted
In FF only $province gets posted
Reputation Points: 10
Solved Threads: 0
Newbie Poster
StefaRSA is offline Offline
2 posts
since Jul 2009
Jul 3rd, 2009
0

Re: Problem with PhP MySql Ajax dropdown code

Hi there,
Nothing leaps out at me as being wrong with your code, except it being a little incomplete. Eg your php side AJAX file doesn't echo the output or give any of the option elements any values. You could try this: Instead of replacing the entire select element with your ajax call, only replace the <option> elements. Ie, put the "cityDiv" tags inside the select tags and dont return the select tags with the ajax.

Good luck
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009
Jul 3rd, 2009
0

Re: Problem with PhP MySql Ajax dropdown code

P.S Forgot to mention South Africa is the BEST. (Not really, just Jo'burg and Pretoria, but you don't meet too many South Africans in the online community)
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009
Jul 4th, 2009
0

Re: Problem with PhP MySql Ajax dropdown code

hi
i think you need to add id for the all select tag
PHP Syntax (Toggle Plain Text)
  1. <select name="city" id="city">
I hope this solve your problem
Thanks
Last edited by peter_budo; Jul 6th, 2009 at 6:49 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 13
Solved Threads: 15
Junior Poster in Training
Tulsa is offline Offline
77 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: About image mirroring using php
Next Thread in PHP Forum Timeline: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC