Welcome Guest, Not a member yet? Register   Sign In
problem with ajax
#1

[eluser]Bigil Michael[/eluser]
i want to print price in accordance with value change in the select box.

code i used is
javascript
Quote:function getprice(){
var ad_type_id = document.frm_add.ad_type_id;
id = ad_type_id.options[ad_type_id.selectedIndex].value;
document.frm_add.ad_price.length = 0;
document.frm_add.ad_price.options[0] = new Option('Loading...','');
var http = createQCObject();
var ran_no=(Math.round((Math.random()*9999)));
querystring = siteurl+'common/ajaxCommon2.php?functiontype=ad_price&id;='+id;
http.open("GET",querystring,true);
http.onreadystatechange = function(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
document.frm_add.ad_price.length = 0;

if(response){
var newVal = response.split("|");
if(newVal.length>0){

for(i=0;i<newVal.length;i++){

document.frm_add.ad_price.options[i] = new Option(newVal[i], newVal[i]);


}

}
}
}
}
http.send(null);
}

ajaxcommon2.php
Quote:function select_price($id){
$getAll = mysql_query("SELECT id,price FROM ad_type WHERE id = '$id' ");
$display='';
while(list($id, $price) = mysql_fetch_array($getAll)){

$display.="$price|";
}
echo trim($display,'|');
}
my view page
Quote:<select name="ad_type_id">
<option value="">--Select--</option>
&lt;?php
foreach($pack_type as $row)
{
?&gt;
<option value="&lt;?php echo $row['id']?&gt;" &lt;?php echo set_select('ad_type_id',$row['id']);?&gt; >&lt;?php echo $row['package_name']?&gt;</option>
&lt;?php
}
?&gt;
</select>
Quote:<select name="ad_price" id="ad_price" >
<option >0</option>
<option >&lt;?php echo $row['price']?&gt;</option>
</select>
now the code is working well and printing the result in a select box.
my reqirement is
remove the second select box;
that means just print the result,not in a select box;
i tried a lot..... but no result

can any one help me???
thanks in advance...
#2

[eluser]Bigil Michael[/eluser]
can anyone help me????
#3

[eluser]pickupman[/eluser]
Well it appears you are taking the response returned by your ajax call then using:
Code:
document.frm_add.ad_price.options = new Option(newVal, newVal);

To add new option/value pairs to the select box. Just append the response to an html element instead if you are just wanting to display the text. Also, any reason for not using CI syntax in ajaxcommon2.php?

Also, please try using the code button in the editor when posting code. It will make it a lot easier for everyone to read.




Theme © iAndrew 2016 - Forum software by © MyBB