Fed196 Posted April 24, 2011 Share Posted April 24, 2011 Hello: I am new to html, php, mysql and need help. I'm not sure if this is an html or javascript question. I would like a recipe index page that lists all recipes as hyperlinks. By clicking on the hyperlink, it will pull up the full recipe displaying recipe name, ingredients and instructions. I have handled this with a test form, entering the recipe name as text, and clicking on a submit button. It works perfectly. However, I would like to use hyperlinks, instead. With the form below, if I use one hyperlink, it works fine. However, with 2 or more hyperlinks, it does not work. What am I doing wrong? Any assistance would be greatly appreciated! Thank you. Karen <html> <head> <title>Form16 April 11</title> </head> <body style="background-color:cyan"> <h2 style="text-align:center">Recipe Index </h2> <hr> <script language=javascript> function submitPostLink() { document.postlink.submit(); } </script> </head> <body> <form action="test5.php" name=postlink method="post"> <input type="hidden" name="recipe_name" value="Anise Pizzelles"> <a href=# onclick="submitPostLink()">Anise Pizzelles</a> <br> <input type="hidden" name="recipe_name" value="Tea Cookies"> <a href=# onclick="submitPostLink()">Tea Cookies</a> <br> </form> <hr> </body> </html> edit: added blocks Quote Link to comment https://forums.phpfreaks.com/topic/234590-sending-post-data-using-hyperlink/ Share on other sites More sharing options...
tomfmason Posted April 24, 2011 Share Posted April 24, 2011 in the example you are using you have two hidden fields with the same name. which will always use the second hidden field's value. You may need to rethink the way you are doing this. Why don't you just use GET in your script instead of POST. If you did this you could simply link to test5.php?recipe_name=Tea%20Cookies etc. Otherwise you will need to change the value of your hidden input field when the user clicks the link. Like so: <html> <head> <title>Form16 April 11</title> </head> <body style="background-color:cyan"> <h2 style="text-align:center">Recipe Index </h2> <hr> <script language=javascript> function submitPostLink(obj) { document.getElementById('recipe_name').value=obj.innerHTML; document.postlink.submit(); } </script> </head> <body> <form action="test5.php" name=postlink method="post"> <input type="hidden" id="recipe_name" name="recipe_name"> <a href=# onclick="submitPostLink(this)">Anise Pizzelles</a> <br> <a href=# onclick="submitPostLink(this)">Tea Cookies</a> <br> </form> <hr> </body> </html> Also, when posting any code, please use the blocks to wrap it. Quote Link to comment https://forums.phpfreaks.com/topic/234590-sending-post-data-using-hyperlink/#findComment-1205587 Share on other sites More sharing options...
Fed196 Posted April 24, 2011 Author Share Posted April 24, 2011 Thank you tomfmason for your prompt reply. It is greatly appreciated! I will take your suggestions, and update the script. -- Karen Quote Link to comment https://forums.phpfreaks.com/topic/234590-sending-post-data-using-hyperlink/#findComment-1205673 Share on other sites More sharing options...
Fed196 Posted April 28, 2011 Author Share Posted April 28, 2011 tomfmason: Thank you! Thank you! Thank you! The information you provided worked perfectly! -- Karen Quote Link to comment https://forums.phpfreaks.com/topic/234590-sending-post-data-using-hyperlink/#findComment-1207785 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.