javascript - Selected value of auto filled dorp down list is not going to JS page using Ajax / jQuery -
country drop down list displayed database table using php & mysql.
based on selected country, state drop down list auto filled.
on js page, tried alert country , state selected country displayed fine displays first state list no matter whatever state selected on form page.
html form page
<form name="frm_edit" id="frm_edit" novalidate> <div class="control-group form-group"> <div class="controls"> <label>country:</label> <select name="cbo_country" id="cbo_country" onchange="selectstate();"> # countries displayed here db <options> using php , mysql. </select> </div> </div> <div class="control-group form-group"> <div class="controls"> <label>state:</label> <select name="cbo_state" id="cbo_state"> <option value="">-- select state --</option> </select> </div> </div> </form>
.js page
submitsuccess: function($form, event) { event.preventdefault(); // prevent default submit behaviour var cbo_country = $("select#cbo_country").val(); var cbo_state = $("select#cbo_state").val(); //alert($("select#cbo_country").val()); //alert($("select#cbo_state").val()); }
if submit form using standard post , action method without ajax / jquery selected country , state data inserted database table on php process page. in case states list auto filled based on selected country , state selected state list.
<form name="frm_edit" action="./add_p.php" method="post">
if submit form using jquery / ajax method , make state drop down list separate country , select state list correct selected state value passed on js page.
may onchange event issue? or else?
selectstate function
states array: 1,13,'alabama',1,14,'alaska',1,15,'arizona',1,16,'arkansas',1,5,'california',1,17,'colorado',1,18,'connecticut',1,19,'delaware',1,20,'florida',1,21,'georgia',1,22,'hawaii',1,23,'idaho',1,24,'illinois',1,25,'indiana',1,26,'iowa',1,27,'kansas',1,28,'kentucky',1,29,'louisiana',1,30,'maine',1,31,'maryland',1,32,'massachusetts',1,33,'michigan',1,34,'minnesota',1,35,'mississippi',1,36,'missouri',1,37,'montana',1,38,'nebraska',1,39,'nevada',1,40,'new hampshire',1,4,'new jersey',1,41,'new mexico',1,1,'new york',1,42,'north carolina',1,43,'north dakota',1,44,'ohio',1,45,'oklahoma',1,46,'oregon',1,8,'orlando',1,47,'pennsylvania',1,48,'rhode island',1,49,'south carolina',1,50,'south dakota',1,51,'tennessee',1,52,'texas',35,59,'toronto',1,53,'utah',1,54,'vermont',1,55,'virginia',1,10,'washington',1,56,'west virginia',1,57,'wisconsin',1,58,'wyoming' <script language="javascript" type="text/javascript"> statearray=new array(<?php print($str_statevalues) ?>) function selectstate(arg) { var_pkid=document.frm_edit.cbo_country.options[document.frm_edit.cbo_country.selectedindex].value; document.frm_edit.cbo_state.options.length=0; payee_state_pkid=0; <?php if($previously_selected_payeestatepkid_from_db > 0) { ?> payee_state_pkid=<?php print($previously_selected_payeestatepkid_from_db) ?>; <?php } ?> for(cnt=0;cnt<statearray.length;cnt=cnt+3) { if(statearray[cnt]==var_pkid) { state_pkid=statearray[cnt+1]; state_name=statearray[cnt+2]; document.frm_edit.cbo_state.options.length=document.frm_edit.cbo_state.options.length+1; document.frm_edit.cbo_state.options[document.frm_edit.cbo_state.options.length-1].value=state_pkid; document.frm_edit.cbo_state.options[document.frm_edit.cbo_state.options.length-1].text=state_name; if(state_pkid==payee_state_pkid) { document.frm_edit.cbo_state.options[document.frm_edit.cbo_state.options.length-1].selected=true; } } } if(document.frm_edit.cbo_state.options.length==0) { document.frm_edit.cbo_state.options.length=document.frm_edit.cbo_state.options.length+1; document.frm_edit.cbo_state.options[document.frm_edit.cbo_state.options.length-1].value=0; document.frm_edit.cbo_state.options[document.frm_edit.cbo_state.options.length-1].text="no states available"; } } function preloadstates() { selectstate('payee') } </script> <body onload="preloadstates();">
Comments
Post a Comment