zszucs Posted October 31, 2008 Share Posted October 31, 2008 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 https://forums.phpfreaks.com/topic/130835-responsetext-doesnt-output-to-textbox/ Share on other sites More sharing options...
zenag Posted October 31, 2008 Share Posted October 31, 2008 remove eval function from ... document.form1.cur_code.value = req.responseText; Link to comment https://forums.phpfreaks.com/topic/130835-responsetext-doesnt-output-to-textbox/#findComment-679090 Share on other sites More sharing options...
zszucs Posted October 31, 2008 Author Share Posted October 31, 2008 remove eval function from ... document.form1.cur_code.value = req.responseText; thanks but that doesn't work Link to comment https://forums.phpfreaks.com/topic/130835-responsetext-doesnt-output-to-textbox/#findComment-679168 Share on other sites More sharing options...
zszucs Posted October 31, 2008 Author Share Posted October 31, 2008 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 https://forums.phpfreaks.com/topic/130835-responsetext-doesnt-output-to-textbox/#findComment-679195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.