943,789 Members | Top Members by Rank

Ad:
Jun 17th, 2009
0

<select> drop down and window.location

Expand Post »
hi all

i have two dynamic drop downs of dealer id and category id which work properly with window.location

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var dealerid;
  2. function getList(xyz)
  3. {
  4. window.location='manage_products.php?category_id=' + xyz;
  5. }
  6. function getProducts(dealer_id)
  7. {
  8. var catid=document.form1.category.value;
  9. window.location='manage_products.php?dealer_id=' + dealer_id + "&category_id="+catid ;
  10. }

but now i want to add static drop down of sub category and make use of window.location which i m not able to do

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <select name="sub_catg" onchange="getSb(this.value)" id="sub_catg">
  2. <option>Select Sub Category</option>
  3. <option value="Batteries">Batteries</option>
  4. <option value="Leather & PU Cases">Leather &amp; PU Cases</option>
  5. <option value="Crystal & Rubber Coated Cases">Crystal &amp; Rubber Coated Cases</option>
  6. <option value="Car Mounts & USB Cradles">Car Mounts &amp; USB Cradles</option>
  7. <option value="AC Chargers & Car Chargers">AC Chargers &amp; Car Chargers</option>
  8. </select>

This is function that is not working
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="javascript">
  2. var subid=document.form1.sub_catg.value;
  3. function getSb(subid)
  4. {
  5. window.location='manage_products.php?dealer_id=' + dealer_id + "&category_id="+catid + "&sub_catg=" + subid ;
  6. }
  7. </script>

vineet
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vinpkl is offline Offline
7 posts
since Nov 2008
Jun 17th, 2009
0

Re: <select> drop down and window.location

All the 3 functions must be nested, so that it will be able to work on changing the current location of your window.

From this demo, the 3 <select> elements, have the same values and options, and copied from your posted code.

- Reset all values and options as needed.

Here's the code:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html id="html40L" lang="en">
  4. <head>
  5. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <meta http-equiv="Content-Style-Type" content="text/css">
  8. <meta http-equiv="Content-Script-Type" content="text/javascript">
  9. <meta http-equiv="Window-target" content="_top">
  10. <title>Free Live Help!</title>
  11.  
  12. <script type="text/javascript">
  13. <!--
  14.  
  15. var Combo = function( subid, dealer_id, category_id ) {
  16. this.subid = subid;
  17. this.dealer_id = dealer_id;
  18. this.category_id = category_id;
  19. };
  20.  
  21. Combo.prototype = {
  22. url : "manage_products.php?",
  23. getValue : function( ids ) {
  24. this.whatID = (( document.getElementById ) ? document.getElementById( ids ) : document.all[ ids ] ).value;
  25. return encodeURIComponent( this.whatID );
  26. },
  27. subid : this.subid,
  28. dealer_id : this.dealer_id,
  29. category_id : this.category_id,
  30. go : function( where ) {
  31. window.location = where;
  32. },
  33. getList : function() {
  34. this.go( this.url + "dealer_id=" + this.getValue( this.dealer_id ));
  35. },
  36. getProducts : function() {
  37. this.go( this.url + "dealer_id=" + this.getValue( this.dealer_id ) + "&category_id=" + this.getValue( this.category_id ));
  38. },
  39. getSb : function() {
  40. this.go( this.url + "dealer_id=" + this.getValue( this.dealer_id ) + "&category_id=" + this.getValue( this.category_id ) + "&sub_catg=" + this.getValue( this.subid ))
  41. }
  42. };
  43.  
  44. var browse = new Combo("sub_catg", "dealer_id", "category_id"); // Specify the Ids of the three <select> elements, referred as the 3 parameters inside the browse object.
  45.  
  46. // -->
  47. </script>
  48. </head>
  49. <body>
  50. <div>
  51. <form id="form1" name="form1" action="#" onsubmit="return false;">
  52. <div>
  53. <label for="dealer_id">Get Products: <select id="dealer_id" name="dealer_id" onchange="browse.getList();">
  54. <option>Select Sub Category</option>
  55. <option value="Batteries">Batteries</option>
  56. <option value="Leather & PU Cases">Leather &amp; PU Cases</option>
  57. <option value="Crystal & Rubber Coated Cases">Crystal &amp; Rubber Coated Cases</option>
  58. <option value="Car Mounts & USB Cradles">Car Mounts &amp; USB Cradles</option>
  59. <option value="AC Chargers & Car Chargers">AC Chargers &amp; Car Chargers</option>
  60. </select></label><br><br>
  61. <label for="category_id">Category: <select id="category_id" name="category_id" onchange="browse.getProducts();">
  62. <option>Select Sub Category</option>
  63. <option value="Batteries">Batteries</option>
  64. <option value="Leather & PU Cases" selected>Leather &amp; PU Cases</option>
  65. <option value="Crystal & Rubber Coated Cases">Crystal &amp; Rubber Coated Cases</option>
  66. <option value="Car Mounts & USB Cradles">Car Mounts &amp; USB Cradles</option>
  67. <option value="AC Chargers & Car Chargers">AC Chargers &amp; Car Chargers</option>
  68. </select></label><br><br>
  69. <label for="sub_catg">Sub Category: <select id="sub_catg" name="sub_catg" onchange="browse.getSb();">
  70. <option>Select Sub Category</option>
  71. <option value="Batteries">Batteries</option>
  72. <option value="Leather & PU Cases">Leather &amp; PU Cases</option>
  73. <option value="Crystal & Rubber Coated Cases" selected>Crystal &amp; Rubber Coated Cases</option>
  74. <option value="Car Mounts & USB Cradles">Car Mounts &amp; USB Cradles</option>
  75. <option value="AC Chargers & Car Chargers">AC Chargers &amp; Car Chargers</option>
  76. </select></label>
  77. </div>
  78. </form>
  79. </div>
  80. </body>
  81. </html>

try to run the whole document first, before you apply modification on the code.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

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 JavaScript / DHTML / AJAX Forum Timeline: vertical alignment question
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: error 800a0400 line: 1 char: 1





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


Follow us on Twitter


© 2011 DaniWeb® LLC