php - Get response <select> and show it in form <select> -
i have form in have list of indian states , cities. on selecting 1 of states, cities state displayed in <select>
show cities. using php script hosted somewhere (a similar website) , think can solve purpose. script takes value
of state options
parameter , returns <select>
corresponding cities.
the script http://www.indane.co.in/state.php?stateid=2196
2196
id/value of selected state.
i need display contents of in cities' .
please suggest me how can this.
so far have tried this,
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> <script language="javascript"> function showcat(id,ss,type) { var cid=id.value; if(type=='state') { document.getelementbyid("state_loading").style.visibility="visible"; var response = httpget("http://www.indane.co.in/state.php?stateid="+cid); var id=document.getelementbyid('bgcity'); id.innerhtml=response; } } function httpget(theurl) { var xhrobject = new xmlhttprequest(); var url = theurl; xhrobject.open("get", url, true); xhrobject.send(); xhrobject.onreadystatechange = function () { if (xhrobject.readystate==4 && xhrobject.status==200) { var response = xhrobject.responsetext; return response; } } } </script> </head> <body> <select name="bgstate" id="bgstate" style="width:200px" onchange="showcat(this,'sub1','state');"> <option value="">[ select state ]</option> <option value="2169" >andhra pradesh</option> <option value="2196" >arunachal pradesh</option> <option value="2170" >assam</option> <option value="2171" >bihar</option> <option value="5267" >chhattisgarh</option> <option value="2174" >delhi</option> <option value="2199" >goa</option> <option value="2175" >gujarat</option> <option value="2176" >haryana</option> <option value="2177" >himachal pradesh</option> <option value="2178" >jammu , kashmir</option> <option value="5268" >jharkhand</option> <option value="2185" >karnataka</option> <option value="2179" >kerala</option> <option value="2181" >madhya pradesh</option> <option value="2182" >maharashtra</option> <option value="2183" >manipur</option> <option value="2184" >meghalaya</option> <option value="2197" >mizoram</option> <option value="2186" >nagaland</option> <option value="2187" >orissa</option> <option value="2189" >punjab</option> <option value="2190" >rajasthan</option> <option value="2195" >sikkim</option> <option value="2191" >tamil nadu</option> <option value="2192" >tripura</option> <option value="5269" >union territory</option> <option value="2193" >uttar pradesh</option> <option value="5259" >uttaranchal</option> <option value="2194" >west bengal</option> </select> <span id="state_loading" style="visibility:hidden;"><img src="http://www.indane.co.in/images/ajax_small_load.gif" /></span> </td> </tr> <br/> <tr valign="top"> <td> </td> <td height="25" >city <span class="error">*</span></td> <td colspan="2"> <span id="sub1"> <select name="bgcity" style="width:200px" id="bgcity" > <option value="">[select city]</option> </select> </span> <span id="city_loading" style="visibility:hidden;"><img src="http://www.indane.co.in/images/ajax_small_load.gif" /></span> <input type="button" value="search" onclick="showcat(document.getelementbyid('bgcity'),'sub2','city');" style="cursor:pointer;" /> </tr> </body> </html>
problem 1-the problem url city dropdown returning selectbox , replacing options of selectbox in page selectbox
another problem access-control-allow-origin header.
replace city drop down in page following
<span id="bgcity"> <select name="bgcity" style="width:200px" > <option value="">[select city]</option> </select> </span>
change showcat as
function showcat(id,ss,type) { var cid=id.value; if(type=='state') { document.getelementbyid("state_loading").style.visibility="visible"; var response = httpget("http://www.indane.co.in/state.php?stateid="+cid); if(response !== undefined) { var id=document.getelementbyid('bgcity'); id.innerhtml=response; } } }
i have removed id associated select box span replaces whole drop down..and remove second parameter in showcat function change give error...
Comments
Post a Comment