Satch
10-31-2008, 12:25 AM
using prototype to do an autopopulate. select from a drop list
* screwed up the title sorry, getting late *
so i'm using prototype to do an autopopulate. select from a drop list and then a textbox is supposed to get filled. it works fine if it's going into a div but it doesn't work for a text box for some reason. the code is a little flaky but it does work for a div
file 1
Code:
<html>
<head>
<title>Changing textbox value based on dropdown list using Ajax and PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="ajax.js"></script>
<script src="prototype.js"></script>
<script>
function sendRequest() {
new Ajax.Request("ajax.php",
{
method: 'post',
postBody: 'id='+ $F('id'),
onComplete: showResponse
});
}
function showResponse(req){
$('fadeBlock').innerHTML= req.responseText;
//document.form1.cur_code.value = 'asdfad';
document.form1.cur_code.value = eval(req.responseText);
//document.getElementById('cur_code').value=req.responseText;
//$F('cur_code').value = 'asdf';
}
</script>
</head>
<body style="font: 12px Verdana, Arial, Helvetica, sans-serif;">
<div id="fadeBlock"></div>
<?php
$sql = "SELECT * FROM product WHERE productid =11749";
$result = mysql_query($sql);
?>
<form style="text-align:center" method="post" action="" name="form1" id="form1">
<p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p>
<p>Country : <select name="id" onChange="sendRequest()" id="id">
<option value="">Select Country</option>
<?php
while($row = mysql_fetch_array($result)) {
echo "<option value=\"$row[productid]\">$row[prodname]</option>\n";
}
?>
</select><br/><br/>
Currency : <input type="text" name="cur_code" id="cur_code" ></p>
</form>
</body>
</html>
ajax file getting called
Code:
<?php
include_once('functions.php');
$sql = "SELECT * FROM product WHERE id =11749";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row[productid];
?>
insights are appreciated
Last edited by Satch : 10-31-2008 at 12:30 AM.
* screwed up the title sorry, getting late *
so i'm using prototype to do an autopopulate. select from a drop list and then a textbox is supposed to get filled. it works fine if it's going into a div but it doesn't work for a text box for some reason. the code is a little flaky but it does work for a div
file 1
Code:
<html>
<head>
<title>Changing textbox value based on dropdown list using Ajax and PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="ajax.js"></script>
<script src="prototype.js"></script>
<script>
function sendRequest() {
new Ajax.Request("ajax.php",
{
method: 'post',
postBody: 'id='+ $F('id'),
onComplete: showResponse
});
}
function showResponse(req){
$('fadeBlock').innerHTML= req.responseText;
//document.form1.cur_code.value = 'asdfad';
document.form1.cur_code.value = eval(req.responseText);
//document.getElementById('cur_code').value=req.responseText;
//$F('cur_code').value = 'asdf';
}
</script>
</head>
<body style="font: 12px Verdana, Arial, Helvetica, sans-serif;">
<div id="fadeBlock"></div>
<?php
$sql = "SELECT * FROM product WHERE productid =11749";
$result = mysql_query($sql);
?>
<form style="text-align:center" method="post" action="" name="form1" id="form1">
<p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p>
<p>Country : <select name="id" onChange="sendRequest()" id="id">
<option value="">Select Country</option>
<?php
while($row = mysql_fetch_array($result)) {
echo "<option value=\"$row[productid]\">$row[prodname]</option>\n";
}
?>
</select><br/><br/>
Currency : <input type="text" name="cur_code" id="cur_code" ></p>
</form>
</body>
</html>
ajax file getting called
Code:
<?php
include_once('functions.php');
$sql = "SELECT * FROM product WHERE id =11749";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row[productid];
?>
insights are appreciated
Last edited by Satch : 10-31-2008 at 12:30 AM.
