Jump to content

responseText doesn't output to textbox


zszucs

Recommended Posts

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

<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

<?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

Link to comment
Share on other sites

my bad

document.form1.cur_code.value = req.responseText;

 

actually works in a way.  there was a large amount of space and then code and then the actual response that i wanted.  with the large amount of space, i just assumed there was no output

here's what was outputted in the text box

							 <!-- //javascript functions, then php functions   --><script>function preparehtml(whichdiv){//alert("preparing");//alert("preparing" + whichdiv);document.all("htmlfromdiv").value=document.all(whichdiv).innerHTML;document.all("prepared").value=whichdiv;}function preparetextarea(whichdiv){//alert("preparing");alert("preparing" + whichdiv);document.all("htmlfromdiv").value=document.all(whichdiv).value;document.all("prepared").value=whichdiv;}</script><SCRIPT LANGUAGE='JAVASCRIPT' TYPE='TEXT/JAVASCRIPT'> <!--/****************************************************     AUTHOR: WWW.CGISCRIPT.NET, LLC     URL: http://www.cgiscript.net     Use the code for FREE but leave this message intact.     Download your FREE CGI/Perl Scripts today!     ( http://www.cgiscript.net/scripts.htm )****************************************************/var win=null;//MO 2004/02/16 Modified function to take additional variables for scrollbarsfunction NewWindow(mypage,myname,w,h,pos,infocus,sbars){if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=" + sbars + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,titlebar=no";win=window.open(mypage,myname,settings);win.focus();}//MOfunction NewWindowdebug(mypage,myname,w,h,pos,infocus){if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=yes,resizable=yes,titlebar=yes";win=window.open(mypage,myname,settings);win.focus();}//MO 2004/02/16 Modified function to take additional variables for window sizefunction CMS_PopUp(msgid, typeid){if (typeid==null) {	NewWindow('/site/cms_popup.php?msgid='+msgid,'cms_popupwindow','390','220','null','front','no');}else if (typeid==1) {	NewWindow('/site/cms_popup.php?msgid='+msgid,'cms_popupwindow','400','400','null','front','no');}else if (typeid==2) {	NewWindow('/site/cms_popup.php?msgid='+msgid,'cms_popupwindow','500','500','null','front','yes');}}//MO// --></script>11749 111

the only thing i want is right at the end after </script> - 11749 111.  is there a way I can just get that?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.