Ajax Example in coldfusion
<script type="text/javascript">
function showvalues(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","?city_name="+str,true);
xmlhttp.send();
}
</script>
<cfparam name="url.city_name" default="">
<div id="txtHint">City info will be listed here...
<cfform>
<cfselect id="city_name" name="city_name" size="1" required="yes" message="Please Select city_name" onchange="showvalues(this.value);" width="120">
<option value="" selected="selected">Please select </option>
<option <cfif url.city_name eq 'City1'>selected="selected"</cfif> value="City1">City1</option>
<option <cfif url.city_name eq 'City2'>selected="selected"</cfif>value="City2">City2</option>
<option <cfif url.city_name eq 'City3'>selected="selected"</cfif>value="City3">City3</option>
</cfselect>
<cfif isdefined('city_name') and city_name eq 'City1'>
<cfselect id="sub_city_name" name="sub_city_name" size="1" required="yes" message="Please Select Sub city_name" width="120">
<option value="City11">City11</option>
<option value="City12">City12</option>
<option value="City13">City13</option>
</cfselect>
</cfif>
<cfif isdefined('city_name') and city_name eq 'City2'>
<cfselect id="sub_city_name" name="sub_city_name" size="1" required="yes" message="Please Select Sub city_name" width="120">
<option value="City21">City21</option>
<option value="City22">City22</option>
<option value="City23">City23</option>
</cfselect>
</cfif>
<cfif isdefined('city_name') and city_name eq 'City3'>
<cfselect id="sub_city_name" name="sub_city_name" size="1" required="yes" message="Please Select Sub city_name" width="120">
<option value="City31">City31</option>
<option value="City32">City32</option>
<option value="City32">City32</option>
</cfselect>
</cfif>
</cfform>
</div>
function showvalues(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","?city_name="+str,true);
xmlhttp.send();
}
</script>
<cfparam name="url.city_name" default="">
<div id="txtHint">City info will be listed here...
<cfform>
<cfselect id="city_name" name="city_name" size="1" required="yes" message="Please Select city_name" onchange="showvalues(this.value);" width="120">
<option value="" selected="selected">Please select </option>
<option <cfif url.city_name eq 'City1'>selected="selected"</cfif> value="City1">City1</option>
<option <cfif url.city_name eq 'City2'>selected="selected"</cfif>value="City2">City2</option>
<option <cfif url.city_name eq 'City3'>selected="selected"</cfif>value="City3">City3</option>
</cfselect>
<cfif isdefined('city_name') and city_name eq 'City1'>
<cfselect id="sub_city_name" name="sub_city_name" size="1" required="yes" message="Please Select Sub city_name" width="120">
<option value="City11">City11</option>
<option value="City12">City12</option>
<option value="City13">City13</option>
</cfselect>
</cfif>
<cfif isdefined('city_name') and city_name eq 'City2'>
<cfselect id="sub_city_name" name="sub_city_name" size="1" required="yes" message="Please Select Sub city_name" width="120">
<option value="City21">City21</option>
<option value="City22">City22</option>
<option value="City23">City23</option>
</cfselect>
</cfif>
<cfif isdefined('city_name') and city_name eq 'City3'>
<cfselect id="sub_city_name" name="sub_city_name" size="1" required="yes" message="Please Select Sub city_name" width="120">
<option value="City31">City31</option>
<option value="City32">City32</option>
<option value="City32">City32</option>
</cfselect>
</cfif>
</cfform>
</div>
Comments
Post a Comment