views:

116

answers:

2

I have a number of input fields that I would like to enable or disable based on the state of a checkbox. Specifically, any fields with IDs beginning with "ship1" I would like to find and disable them when the box is checked. Anyone know how?

Here's a snippet of my page:

  <div id="tabs-1">
          <fieldset>
            <legend>Shipping address(es)</legend>
            <table style="text-align: left; width: 100px;" border="0" cellpadding="2" cellspacing="2">
              <tbody>
                <tr>
                  <td>
                    Clinic name<br>
                    <input maxlength="25" size="25" tabindex="6" name="ship1ClinicName" id="ship1ClinicName" onkeyup="javascript:setTabTitle(this.value);">
                  </td>
                  <td>
                    <div align="right"><input type=checkbox name="sameAsMailing" checked onchange="javascript:sameAsMailingChanged(this.checked)">Same as mailing</input></div>
                  </td>
                </tr>
                <tr>
                  <td>
                    Street 1<br>
                    <input maxlength="25" size="25" tabindex="7" name="ship1Street1">
+3  A: 

This should find the fields you're interested in:

$("input[id^='ship1']")
Sixten Otto
+1  A: 
$("input[id^='ship1']").attr('disabled', 'disabled');

Hope it helps.

Braveyard