Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a value from a text box before submitting

Status
Not open for further replies.

rjseals

Technical User
Nov 25, 2002
63
US
I have a question in regards to getting a value from a text box before actually submitting the form (and getting it in a variable)

Example:

<form method="post" action="nextpage.php">
<input type="text" name="value1">
.....(further down the page)....
I want to build a sql statement based on what the user entered in the text box value1
$sql=mysql_query("select * from TABLE where VALUE="VALUE ENTERED IN TEXT BOX ABOVE");

Any Ideas?

Thanks.
 
You can't get the value of a text box in PHP until the form is submitted. This is because PHP runs on the server, not the client.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
yup,
why not execute the statement in the page to which this textfield is submitted???

Known is handfull, Unknown is worldfull
 
Yeah that is what I was going to do if I could find no solution.

Thanks
 
if you must do it on the form entry page itself, then needs must that you use javascript. you should post a query in that forum.
 
sleipnir214 mentions the issue you have in doing it this way. PHP is executed on the server then the HTML is sent to the client browser. On the client browser you can use JavaScript yet you still have to get the code back to the server in order to execute the PHP. See the dilemma? This can only be done by submitting the page or a page. There is the option of using a frame, iframe or a popup to accomplish this task.

If you wish to do it without the users interaction you can open a new can of worms. I deal with fraud at work where fraudsters use this sort of thing for identity theft. Get caught using this method by users with any sensitive information and you can find yourself and/or your website treated like spyware or much worse.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top