miligraf Posted October 29, 2007 Share Posted October 29, 2007 Is it posible to get a optgroup label in a variable with php? Example: <form action="" method="post" enctype="multipart/form-data"> <select name="color"> <optgroup label="Light colors"> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Yellow">Yellow</option> <optgroup> </form> That way i can have the variables (example) Category: Light Colors (optgroup) and Color: Red. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/75170-solved-get-the-optgroup-label-in-a-variable/ Share on other sites More sharing options...
Psycho Posted October 29, 2007 Share Posted October 29, 2007 No. Optgroup elements are only for client-side purposes. One solution is to include the option group label as part of the values. <select name="color"> <optgroup label="Light colors"> <option value="Light Color-Red">Red</option> <option value="Light Color-Blue">Blue</option> <option value="Light Color-Green">Green</option> <option value="Light Color-Yellow">Yellow</option> <optgroup> </select> Then in the PHP you can parse the value to separate the two values: <?php $colorInput = explode('-', $_POST['color']); $color = $colorInput[0]; $colorLabel = $colorInput[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75170-solved-get-the-optgroup-label-in-a-variable/#findComment-380161 Share on other sites More sharing options...
miligraf Posted October 30, 2007 Author Share Posted October 30, 2007 Thx!, works perfect. Quote Link to comment https://forums.phpfreaks.com/topic/75170-solved-get-the-optgroup-label-in-a-variable/#findComment-381572 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.