Schlo_50 Posted May 29, 2008 Share Posted May 29, 2008 Hi all, I am having a problem with a certain hidden field. This hidden field needs to hold the value $name, but I don't want it to be inside my foreach loop. However, If I have it outside of my foreach loop the variable $name isn't assigned the value it is meant to. Im not sure how else to explain this, so my code is as follows. It should become clearer when you see the commented line I have included. print "<select name=\"manufacturer\" class=\"form\">"; print "<option value=\"none\" selected=\"selected\">Not Applicable</option>"; $linesb = file("data/manufacturers.DAT"); foreach ($linesb as $lineb) { $datab = explode("|", $lineb); $mid = trim($datab[0]); $name = trim($datab[1]); print "<option value=\"$mid\">$name</option>"; } // $name below takes on the last value in my .DAT list because it is outside of the loop. print "<input type=\"hidden\" name=\"manhide\" value=\"$name\" class=\"form\">"; print "</select>"; Thanks in advance guys! Quote Link to comment https://forums.phpfreaks.com/topic/107776-having-a-little-problem/ Share on other sites More sharing options...
Daniel0 Posted May 29, 2008 Share Posted May 29, 2008 However, If I have it outside of my foreach loop the variable $name isn't assigned the value it is meant to. What value is it supposed to hold? Quote Link to comment https://forums.phpfreaks.com/topic/107776-having-a-little-problem/#findComment-552447 Share on other sites More sharing options...
Schlo_50 Posted May 29, 2008 Author Share Posted May 29, 2008 It is meant to hold the option the user selects using the drop down menu I have generated. print "<option value=\"$mid\">$name</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/107776-having-a-little-problem/#findComment-552515 Share on other sites More sharing options...
ILYAS415 Posted May 29, 2008 Share Posted May 29, 2008 try putting the hidden input outside the select box. thats probably why. Quote Link to comment https://forums.phpfreaks.com/topic/107776-having-a-little-problem/#findComment-552524 Share on other sites More sharing options...
Schlo_50 Posted May 29, 2008 Author Share Posted May 29, 2008 Good idea, but that hasn't solved the problem. Anybody else? Quote Link to comment https://forums.phpfreaks.com/topic/107776-having-a-little-problem/#findComment-552539 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.