ebolt007 Posted May 24, 2012 Share Posted May 24, 2012 I have a form where I have a dropdown with all 50 states. The value for each options is the State abbreviation. Now I have an input area that needs the name to change if the state is selected as SD so the shipping can be different where this form posts too. I'm not sure how to change an input name tho. I was trying something like below. <script language="javascript" type="text/javascript"> $(document).ready(function () { $('.group').hide(); $('#option').show(); $('#state').change(function () { $('.group').hide(); $('#option'+$(this).val()).show(); }) }); </script> Then inside my form I would do. <td>State</td><td> <?echo "<select id=\"state\" name=\"xxxState\">\n"; $state_query = mysql_query("SELECT * FROM State"); while ($state_row = mysql_fetch_assoc($state_query)) { $State = $state_row['State']; echo"<option value=\"$State\">$State</option>"; } ?> </select> <td> <td>Quantity</td><td> <div id="option" class="group"><input type="text" size="1" value="0" name="QuantityBook1"></div> <div id="optionSD" class="group"><input type="text" size="1" value="2" name="QuantityBookSD"></div> </td> But that javascript obviously would only hide and show the div's, which I guess might work, but wouldn't those values still be passed? So I need to actually remove and add the names. Plus my script above would only work if I had 50 inputs and then pulled the id's for each and only changed the SD one to the "QuantityBookSD". Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/263077-change-input-name-on-selection-change-in-a-drop-down/ Share on other sites More sharing options...
requinix Posted May 24, 2012 Share Posted May 24, 2012 I don't understand why you have to change the input name. Can't you just figure that out in the script? It's not like the form submission can be trusted anyways. Quote Link to comment https://forums.phpfreaks.com/topic/263077-change-input-name-on-selection-change-in-a-drop-down/#findComment-1348432 Share on other sites More sharing options...
haku Posted May 27, 2012 Share Posted May 27, 2012 Yeah, you are better doing your logic on the server side after submission - the way you are trying to do it is adding security risks. Quote Link to comment https://forums.phpfreaks.com/topic/263077-change-input-name-on-selection-change-in-a-drop-down/#findComment-1348865 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.