Page 1 of 1

set textbox value with php

Posted: Tue Apr 15, 2008 9:51 pm
by jubairarifctg
Hi there

I have a textbox in my php page like this

Code: Select all

<li><B>1.</B> planetlab1.cs.uchicago.edu [University of Chicago]:
<br><input type="text" id="radius1" style="width:50px;" title="Type your radius in km" value="0"/>km
Now I have another php function

Code: Select all

function valueInsert($tname, $tdist){
 
echo "<br>From valueInsert<br>";
echo $tname;
 
if ($tname=="planetlab1.cs.uchicago.edu")
        document.getElementById("radius1").value=$tdist;
 
 
}
After searching to mysql, I want to setup a value in my textbox radius1 inside the function valueInsert. However, it is not working. I guess I am making confusion with server end and client end concept. Can anyone help me to get it right. If not php, how can I populate my textbox after searching a data from mysql?

Re: set textbox value with php

Posted: Wed Apr 16, 2008 3:08 am
by Phoenixheart
Yes, you're confused between server and client scripts. document.getElementById() etc. is a Javascript function.
You just need to do something like this:

Code: Select all

 
$value = get_data_from_mysql(); // do your mysql stuffs here 
echo '<input type="text" id="radius1" style="width:50px;" title="Type your radius in km" value="' . addslashes($value) . '"/>';