javascript - Keep $_GET value of a drop down menu after submitting the form -


edited:

demo: http://jsfiddle.net/53gkh/6/

i have 2 drop down menu's in html:

first 1 car brand:(is working fine)

<form action="car-list.php" method="get"> <select name="search" id="main_list" > <option value="bmw"<?php if ($_get['search']== 'bmw') {echo "selected='selected'"; }   ?>>bmw</option> </select> </form> 

after user choose brand second drop down menu 'activated' choose model of car:

<select  name="model"  id="brand" class="secondary"> <option disabled selected> kies </option> </select> 

to 'activate' second drop down menu im using following js code:

$(function() { var sel, i,     list = ['aixman', 'alfaromeo', 'bmw'],     aixman = ['aixman'],     alfaromeo = ['33', '75'],     bmw= ['1-serie','3-serie','4-serie','5-serie','6-serie'],     astonmartin = ['cygnet', 'db7'],      dev_default = '<option value="default" selected>kies</option>',    sel_brand = $('#brand'); sel_version = $('#version');  $('select').change(function() {     switch (this.id) {         case 'main_list':             sel_brand.find('option').remove();             sel_brand.append(dev_default);             sel_brand.show();             if (this.value == 'bmw') {                 (i = 0; < bmw.length; i++) {                     $("#brand").append(                         '<option value="' + bmw[i] + '">' + bmw[i] + '</option>'                     );                         }              }             break;      } });  }); //end document.ready() 

i have updated js code: how can echo selected value of second dropbox menu after submitting/refreshing page?

i suggest change server-side php code accommodate functionality.

steps:

  1. whenever form submitted, using menu 1 selection, values menu 2 , set in variable.
  2. in html of second menu, check if variable in step 1 isset(), , if yes, create html options of menu 2 in loop. also, while doing so, using selected value form submission, pre-select option. else if empty(), nothing.

when user making selection in menu 1, javascript kick in , task. , whenever form submitted, pre-create menu 2.

hope gets going in right direction. kindly ask if face difficulty in implementing.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -