phpnewbie112 Posted December 6, 2008 Share Posted December 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/ Share on other sites More sharing options...
redarrow Posted December 6, 2008 Share Posted December 6, 2008 you mean this ..... <?php if($txtAmount){ //do somethink }else{ //dont do nothink } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707471 Share on other sites More sharing options...
phpnewbie112 Posted December 6, 2008 Author Share Posted December 6, 2008 I mean the dropdown is called txtAmount, what do I have to add inside value="" to submit the selected value to my payment gateway Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707473 Share on other sites More sharing options...
redarrow Posted December 6, 2008 Share Posted December 6, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707477 Share on other sites More sharing options...
ashishag67 Posted December 6, 2008 Share Posted December 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707479 Share on other sites More sharing options...
chronister Posted December 6, 2008 Share Posted December 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707481 Share on other sites More sharing options...
redarrow Posted December 6, 2008 Share Posted December 6, 2008 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']." '>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707484 Share on other sites More sharing options...
phpnewbie112 Posted December 6, 2008 Author Share Posted December 6, 2008 thank you all, I will try all the proposed options but I think a double form as ashishag67 mentioned is better. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/135773-solved-dropdown-send-the-selected-value/#findComment-707503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.