Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.