scooter41 Posted October 25, 2007 Share Posted October 25, 2007 Hi there, is it possible to dynamically set the value of a hidden field on a button? I guess via Javascript? I was passing a prodID value on an image, which worked great in firefox, but then I found out in IE this doesnt work Its fine with a submit button+ value, but this looks ropey and not really what I am after! Im basically trying to prevent having multiple forms with hidden ID's and just 1 form with the ID being set on the BUY ITEM button. You can see the page here: http://www.parts4windows.co.uk/product.php?pID=3490&catID=5 My new idea is to perhaps set the value of the hidden variable prodID dynamically when the user hits buy item. Thanks for any help in advance! Quote Link to comment https://forums.phpfreaks.com/topic/74760-solved-set-the-value-of-a-hidden-field/ Share on other sites More sharing options...
pocobueno1388 Posted October 25, 2007 Share Posted October 25, 2007 Yes you can do that, you don't need JavaScript. <?php $query = "SELECT prodID FROM table WHERE condition"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<input type='hidden' name='prodID' value='{$row['prodID']}'>"; } ?> That was just a quick example on how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/74760-solved-set-the-value-of-a-hidden-field/#findComment-377925 Share on other sites More sharing options...
GingerRobot Posted October 25, 2007 Share Posted October 25, 2007 I think missed the point poco - the particular product ID won't be known until the user clicks a particular button. And yes, it'll be javascript to do this. You'll need to set up a function which will change the value of the hidden field depending on which button is pressed. Quote Link to comment https://forums.phpfreaks.com/topic/74760-solved-set-the-value-of-a-hidden-field/#findComment-377940 Share on other sites More sharing options...
scooter41 Posted October 25, 2007 Author Share Posted October 25, 2007 Thanks guys, yes the prodID is set dependent on which button they click. Are hidden fields accessible by the input name just like other fields? document.formname.inputname.value for example? or do they require some special processing Quote Link to comment https://forums.phpfreaks.com/topic/74760-solved-set-the-value-of-a-hidden-field/#findComment-378004 Share on other sites More sharing options...
scooter41 Posted October 26, 2007 Author Share Posted October 26, 2007 found the answer, you can indeed refere to the form name as any other form element so : <script language="javascript"> function changeVar(changeTo) { var property = document.formname.prodID; property.value=changeTo; alert (property.value); - to return the value to check } </script> see here: http://qa.techinterviews.com/q/20060729110146AAoy4lc Quote Link to comment https://forums.phpfreaks.com/topic/74760-solved-set-the-value-of-a-hidden-field/#findComment-378419 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.