Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » using one text box for different variables (php)
Closed Thread
Old 07-11-2007, 08:48 AM   #1 (permalink)
 
Newb Techie

Join Date: Oct 2006

Posts: 29

zach014

Default using one text box for different variables (php)

i've seen websites use one text box to submit different things depending on which button they click.
for example, i have a buy button and a sell button next to each other, and one text box to the right of them. i want it so that if they click buy, it will read the contents of the text box as if it were a different text box than if someone clicked sell.
thanks in advance,
~zach
zach014 is offline  
Old 07-11-2007, 06:30 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: using one text box for different variables (php)

Hmm, what'cha mean? Like this?

http://www.vormund.net/eg/buysell.php

Click the button, and it'll be echoed out along with the text box. So then you could do a simple
PHP Code:
if ( $_POST['butonName'] ) {
  
// do this
} else {
  
// do this

The code behind buysell.php is very simple:

PHP Code:
<?php 
foreach( $_POST as $var => $val )
  echo 
$var.":".$val."<br>";
?>
<form action="<?= $_SERVER['PHP_SELF'?>" method="post">
  <input type="text" name="stuff"><br>
  <input type="submit" name="buy" value="Buy">
  <input type="submit" name="sell" value="Sell">
</form>
I guess the bottom line is by putting a name on the submit tag, it'll show up as a variable, too.
__________________
Vormund is offline  
Old 07-11-2007, 10:30 PM   #3 (permalink)
 
Newb Techie

Join Date: Oct 2006

Posts: 29

zach014

Default Re: using one text box for different variables (php)

thanks! it worked like a charm!
zach014 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Site Project - Flash + PHP + MySQL + CSS theone_trent Web Graphics, Design, Digital Images 2 06-30-2007 01:12 PM
Need a good captcha generating php script surut Windows Operating Systems and Software 1 05-26-2007 09:23 AM
PHP captcha script needed iorgus Programming Discussions 2 05-20-2007 01:33 PM
PHP 2-player game? thejeremy Programming Discussions 4 04-09-2007 06:01 PM
Remote file access w/ IP + PHP? thejeremy Programming Discussions 2 04-04-2007 05:24 PM