Jump to content

Change input name on selection change in a drop down


ebolt007

Recommended Posts

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.