laxi Posted September 13, 2013 Share Posted September 13, 2013 Hello everyone, In my webpage i have 2 forms. 1 form has 3 select dropdown boxes and the other one is the main form which parses to a php script. I would want the values of my 1st form dropdown select boxes to be passed into a hidden input field in the second form so that I can parse those to mysql database. I am having difficulties passing the value of my 3 dropdown list in 1st form to the main form. Please help and thanks in advance. below are my 2 forms 3 dropdown select form---> <form action="" method="get" name="tripleplay"><table width="65%" border="1"> <tr> <td width="25%" align="right">Category </td> <td width="75%"><select name='List1' id="catg1" onchange="fillSelect(this.value,this.form['List2'])"> <option selected="selected">Make a selection</option> </select></td> </tr> <tr> <td align="right">First-Subcategory </td> <td><select name='List2' id="catg2" onchange="fillSelect(this.value,this.form['List3'])"> <option selected="selected">Make a selection</option> </select></td> </tr> <tr> <td align="right">Second-Subcategory </td> <td><select name='List3' id="catg3" onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected="selected" >Make a selection</option> </select></td> </tr> </table></form> ++++++++++++++++++++++++++++++++++++++++ Main Form---> <form action="inventory_list.php" method="post" enctype="multipart/form-data" name="myForm"><table width="65%" border="1"> <tr> <td align="right" width="25%">Product Name </td> <td width="75%"><input name="product_name" type="text" id="product_name"/></td> </tr> <tr> <td align="right">Price </td> <td> $ <input name="price" type="text" id="price"/></td> </tr> <tr> <td align="right">Details </td> <td><textarea name="details" cols="55" rows="10"> </textarea></td> </tr> <tr> <td align="right">Upload Product Image </td> <td> <input name="imagefile" type="file" /></td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" value="submit" /> <input name="reset" type="reset" value="reset" /> <input name="category" type="hidden" value="cat1"/> <input name="first_subcategory" type="hidden" value="cat2" /> <input name="second_subcategory" type="hidden" value="cat3"/> </td> </tr> </table></form> Again Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/282133-form-issue-unable-to-pass-select-box-value-from-1-form-to-another/ Share on other sites More sharing options...
fastsol Posted September 13, 2013 Share Posted September 13, 2013 Are these 2 forms on the same page? You have the first form posting back to the same page it's on and the second form posting to a different page. If the intention is to fill out the first form and submit it, then fill out the second form and submit that to the other page then you need to grab the $_GET vars form the url after the first submit and put them in the hidden fields of the second form. <input name="category" type="hidden" value="<?php echo (isset($_GET['List1'])) ? $_GET['List1'] : ''; ?>"/> <input name="first_subcategory" type="hidden" value="<?php echo (isset($_GET['List2'])) ? $_GET['List2'] : ''; ?>" /> <input name="second_subcategory" type="hidden" value="<?php echo (isset($_GET['List3'])) ? $_GET['List3'] : ''; ?>"/> Quote Link to comment https://forums.phpfreaks.com/topic/282133-form-issue-unable-to-pass-select-box-value-from-1-form-to-another/#findComment-1449378 Share on other sites More sharing options...
laxi Posted September 13, 2013 Author Share Posted September 13, 2013 Are these 2 forms on the same page? You have the first form posting back to the same page it's on and the second form posting to a different page. If the intention is to fill out the first form and submit it, then fill out the second form and submit that to the other page then you need to grab the $_GET vars form the url after the first submit and put them in the hidden fields of the second form. <input name="category" type="hidden" value="<?php echo (isset($_GET['List1'])) ? $_GET['List1'] : ''; ?>"/> <input name="first_subcategory" type="hidden" value="<?php echo (isset($_GET['List2'])) ? $_GET['List2'] : ''; ?>" /> <input name="second_subcategory" type="hidden" value="<?php echo (isset($_GET['List3'])) ? $_GET['List3'] : ''; ?>"/> Thank you for the quick response. I have both the forms in 1 webpage. The dropdown box values from the first form will need to be passed to the second form which has a submit button to parse to a php script. The first form does not have a submit button.Only the values needs to be passed from 1st form to second form in the same page. Quote Link to comment https://forums.phpfreaks.com/topic/282133-form-issue-unable-to-pass-select-box-value-from-1-form-to-another/#findComment-1449381 Share on other sites More sharing options...
laxi Posted September 13, 2013 Author Share Posted September 13, 2013 What i need is to get values of the 3 dropdowns from the first form to be passed to the second form. The first form has no submit button. Both the forms are on the same page, and only the second form has the submit button which used the values of the 1st form dropdown to then parse to a php script. I think we need some javascript to collect values from 1st forms select boxes and pass them to second form. Not sure how to proceed.. Quote Link to comment https://forums.phpfreaks.com/topic/282133-form-issue-unable-to-pass-select-box-value-from-1-form-to-another/#findComment-1449383 Share on other sites More sharing options...
fastsol Posted September 13, 2013 Share Posted September 13, 2013 If the first form doesn't submit anything then why do you have it as a different form than the second? Why not just put them in the same form and submit it all at once? Is the select boxes in the first form dynamic and gather info as you select down the list? Even if it does, you can put it all in the same form unless you're not telling us some critical part to why you are doing it this way. Quote Link to comment https://forums.phpfreaks.com/topic/282133-form-issue-unable-to-pass-select-box-value-from-1-form-to-another/#findComment-1449404 Share on other sites More sharing options...
mac_gyver Posted September 14, 2013 Share Posted September 14, 2013 Please use the forum's bbcode tags (the edit form's <> button) when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/282133-form-issue-unable-to-pass-select-box-value-from-1-form-to-another/#findComment-1449431 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.