Jump to content

Capturing value of a text box


mtgriffiths

Recommended Posts

Hey All,

 

What i am trying to do is capture the value of a text box.

I cannot do the submit to self as it is inside of a form.

 

I have 2 buttons on my page. The text box is used inside one form but i need to be able to access the value inside the form incase the user presses the other button.

 

I'll try to explain a little better....

 

I have a search page that brings up results in a table. There is a quantity text box that allows the user to enter how many of the searched item they would like. There is a button to add to cart and another button to take the values to a different page.

 

The quantity is currently linked to the cart button but i need to capture the value incase they press the other button.

 

Is this possible...if so could anyone help?

 

Thanks in advance

 

Matthew

Link to comment
https://forums.phpfreaks.com/topic/100893-capturing-value-of-a-text-box/
Share on other sites

<?php
if (isset($_POST['btnSubmit']))
{ 
  $qty = $_POST['qty'];
  switch ($_POST['btnSubmit'])
  {
    case 'Search':
      // do search
      echo "searching";
      break;
    case 'Next page':
      // go to other page
      echo "redirecting";
      break;
  }
}

?>
<form method='post'>
    Quantity : <input type="text" name="qty" size="5" /><br />
    <input type="submit" name="btnSubmit" value="Search" />
    <input type="submit" name="btnSubmit" value="Next page" />
</form> 

I have been looking around but dont know if this is possible...

 

I know that it is possible to get the value of a text box using this javascript code:

 

document.formname.textboxname.value

 

Is there anyway to take the result from this and change it into a variable that i can use?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.