Page 1 of 1

get form element's value in same page using php

Posted: Fri Feb 13, 2009 12:42 pm
by dheeraj
hello again, normally we used to post values of form elements to other page or in database, but here i want to collect its value in the same page without submitting the form, like happens in java script, by using getElementById() method..

Same thing i want to do in php ..

suppose i hve below form say test1.php...

Code: Select all

<form name="test" method="post" action="">
<input type="text" name"t1" id="t1" value="">
<select name="s1">
<option value="cricket">Cricket</option>
<option value="football">Football</option>
</select>
<input type="submit" name"sub1">
</form>
 


now i want to get the values of textfield & combo box in the same page i.e. test1.php, without submitting the form...

Re: get form element's value in same page using php

Posted: Fri Feb 13, 2009 1:54 pm
by sparrrow
You will need to use Javascript to utilize user input without running it back through the server. Javascript runs on the client's machine, which explains why it can work without submitting the form. PHP runs on the server, so the only way to let PHP get ahold of user input is to post the data. If you are trying to avoid the page refresh, you can look into AJAX. AJAX uses javascript to get the form data, post it to the server in the background, and return the results. Not sure what you are attempting to do, but JS is required either way.

Re: get form element's value in same page using php

Posted: Fri Feb 13, 2009 1:57 pm
by watson516
If you just wanted to keep the user on the same page, you could put the current page into the form's action and handle the form at the top of the current page.