Jump to content

[SOLVED] dropdown send the selected value


phpnewbie112

Recommended Posts

Hello, how can I send only a selected value in a dropdown bearing in mind that I cannot use the $_POST['total']

 

I am using a payment gateway, I have to submit in hidden form for example:

 

<input type="hidden" name="txtAmount" value="">

 

where  the value should be extracted from the "selected" value of the dropdown. thanks a million

Link to comment
Share on other sites

try this you mean this mate..........

 


<?php

if($_POST['submit']){

$names=$_POST['names'];

if($names=="john"){

	echo $names;

}else{

	echo "sorry that was not the correct selected item";
}


}

?>

<form method="POST" action="<?php $_SERVER['PHP_SELF']?>">

<select name="names">

<option value="john">john</option>

<option value="terry">terry</option>

<option value="chris">chris</option>

</select>

<br><br>

<input type="submit" name="submit" value="send">

</form>

Link to comment
Share on other sites

What method is paypal asking inorder to process the transaction. You can also use 2 forms instead. i.e. the first form with dropdown will pass the value to the second form wherein you can post the value from the first to the second page where in you can also declare a form variable with hidden field with respective drop down value..

 

//page1.php

<form method=post action=page2.php>
<select name=txtAmt>
<option value="1000">1000</option>
<option value="2000">2000</option>
<input type=submit value="Submit" name=submit>
</form>

//page2.php
<form method=post action="pagename.php">
<input type=hidden name=txtAmount value="<?php echo $_POST['txtAmt'];?>">
<input type=submit name=submit value="Confirm Order">
</form>

 

Hope this helps you also check http://www.mysqlandphp.net

Link to comment
Share on other sites

The way I understand it is that you want a hidden input to be the value of whatever item is selected in a select menu. These are both in the same form and you cannot use $_POST['fieldName'] to fill it in. So therefore the hidden input needs to be valued with javascript.

 

Here is the best i can come up with. I am very very limited with Javascript, but I think this will do what you want.

 

<?php
echo '<pre>'; print_r($_POST); echo '</pre>';

?>
<script type="text/javascript" language="javascript">

function changeIt(selectedItem)
{
var theField = document.getElementById('testing2');

theField.value = selectedItem.value;
}

</script>
<form name="test" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="testing" onChange="javascript:changeIt(this)" >
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
</select>

<input type="hidden" name="testing2" id="testing2" value="" />
<input type="submit" name="submit" value="Submit" />
</form>

 

Hopefully this is what your looking for.

Link to comment
Share on other sites

if it from a database the value then echo the database value

 

<?php

$sql="select * from what_ever";
$res=mysql_query($sql)or die(mysql_error());

while($date=mysql_fetch_assoc($res)){

echo"<input type='hidden' name='txtAmount' value=' ".$data['database_field']." '>"; 
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.