Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing (disabled) text fields onclick

Status
Not open for further replies.

Wulfgen

Technical User
Dec 31, 2004
283
US
Hello All,

I have some form radio buttons and have linked a text field (disabled) to enable when the radio called "purchased_other" is clicked on - then the user can enter whatever data they need....

However... if the text field is enabled and some text is entered, and the user changes their mind and clicks another radio the field is disabled - but the entered data stays there....

Is there a way to have the field "clear" whenever any other radio is clicked on? - I tried to use a form.elements [purchase_other].disabled = clear; and some other different variations but it didnt work - is this possible?


<tr valign="top">
<td>About your new home purchase?<BR>
<span class="core">
<input type="radio" name="purchase" value="Cash Purchase" onClick="this.form.elements['purchase_other'].disabled = !this.unchecked;">
</span> Cash Purchase<BR>
<span class="core">
<input type="radio" name="purchase" value="Financing" onClick="this.form.elements['purchase_other'].disabled = !this.unchecked;">
</span> Financing<BR>
<span class="core">
<input type="radio" name="purchase" value="Other:" onClick="this.form.elements['purchase_other'].disabled = !this.checked;">
</span>Other: <input type="text" class="form" name="purchase_other" size="20" disabled="disabled" /></td>
</tr>
 
Hi

I prefer it with [tt]function[/tt] :
Code:
[red]<script type="text/javascript">
function ch(what)
{
  document.ff.purchase_other.disabled=what
  if (what) document.ff.purchase_other.value=''
}
</script>[/red]

[gray]...[/gray]

<form name="[red]ff[/red]" action="">
<tr valign="top">
                                          <td>About your new home purchase?<BR>
                                              <span class="core">
                                              <input type="radio" name="purchase" value="Cash Purchase" onClick="[red]ch(1)[/red]">
                                              </span> Cash Purchase<BR>
                                              <span class="core">
                                              <input type="radio" name="purchase" value="Financing" onClick="[red]ch(1)[/red]">
                                              </span> Financing<BR>
                                              <span class="core">
                                              <input type="radio" name="purchase" value="Other:" onClick="[red]ch(0)[/red]">
                                              </span>Other: <input type="text" class="form" name="purchase_other" size="20" disabled="disabled" /></td>
                                        </tr>
                                        </form>

Feherke.
 
This works great for one set - this is my mistake - I tried to attach the js to multiple sets of radios and disabled fields in the form but it only works on one set - I tried to duplicate the script for the others but that did'nt work either.

I have five "sets" of radios and disabled fields - fields called respectively, (1)bedroom_other (2) bathroom_other (3) footage_other (4) purchase_other (5) property_other

I have 5 similar radio sets with the onclick event attached to each radio, for each disabled field
 
Hi

Code:
<script type="text/javascript">
function ch([red]which,[/red]what)
{
  document.ff[red][which][/red].disabled=what
  if (what) document.ff[red][which][/red].value=''
}
</script>

...

<form name="ff" action="">
<tr valign="top">
                                          <td>About your new home purchase?<BR>
                                              <span class="core">
                                              <input type="radio" name="purchase" value="Cash Purchase" onClick="ch([red]purchase_other,[/red]1)">
                                              </span> Cash Purchase<BR>
                                              <span class="core">
                                              <input type="radio" name="purchase" value="Financing" onClick="ch([red]purchase_other,[/red]1)">
                                              </span> Financing<BR>
                                              <span class="core">
                                              <input type="radio" name="purchase" value="Other:" onClick="ch([red]purchase_other,[/red]0)">
                                              </span>Other: <input type="text" class="form" name="purchase_other" size="20" disabled="disabled" /></td>
                                        </tr>
                                        </form>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top