View Full Version : pass textbox value to php without submitting form

12-21-2010, 04:26 PM
Good day all:

I want to get the value of a textbox into php without clicking the submit button. Any advice... Here is what I have
My form field:

<input type="text" style=background:transparent; border:0px; name='clientid' >

This field is populated dynamically by its name with another php script in this way

echo "formObj.clientid.value = '".toSafeString($inf["clientID"])."';\n";

Now I want to take the value in code#1 (name='clientid') and pass it to a php code that is in the same file as the form. Here is the php code

$name=$_POST['name'];//this is where the value of the text box mentioned is defined
include 'datalogin.php';

error_reporting(E_ERROR | E_WARNING | E_PARSE);
//get image details
$uploaddir = "images/clientsimages/";

$get_data = "SELECT i.uploadedfile, i.clientid " . " FROM images AS i, ajax_client AS a " . " WHERE i.clientid = a.clientID " . " AND a.clientID = $name";

$get_data_res = mysql_query($get_data) or die(mysql_error() . '<br>sql : '.$get_data);

if (mysql_num_rows($get_data_res) > 0)
while ($get_data_info = mysql_fetch_array($get_data_res))
$uploadedfile = $uploaddir . $get_data_info["uploadedfile"];



I know this may require js, but I appreciate any help!

12-21-2010, 05:11 PM
Search Google for AJAX examples as you will need AJAX to allow Javascript and PHP to communicate and do the job you want it to do.

12-21-2010, 05:31 PM
Thanks for the reply. I'm not using js currently. My question is whether I can use js to be able to get the textbox input value from the form to php code?

Old Pedant
12-21-2010, 07:16 PM
And you got the answer. AJAX. Period. There's no other way.

You might start here:

Look down the page to the category "PHP and AJAX".

Be prepared to start learning JavaScript.

12-21-2010, 08:19 PM
Thank you! looking into it now...