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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get ID of textbox when checkbox has been selected

Status
Not open for further replies.

Clanger67

Programmer
Mar 28, 2002
28
GB
I have a page where when the user clicks on a checkbox I want the text box next to it to become enabled so the user can edit the data inside it.

The checkbox has a unique reference number assigned to it from a database record. There could be up to 5 or 6 checkboxes on the form at the same time and I am using the refernce number as part of the id for both the checkboxes and the textboxes.

so i could have the following:
<input type="text" id=txt+RefNum> <input type="checkbox" id=chk+RefNum>
where RefNum=1234.

I can get the ID of the checkbox, but I dont know how to get the ID of the textbox and change it to enabled.

Any help would be much appreciated.

David
 
Code:
function enableTextBox (obj) {
   var refNum = obj.id.replace(/chk/, "");
   var txtBox = document.getElementById("txt" + refNum);
   txtBox.disabled = (obj.checked) ? "disabled" : "";
}

and for the checkbox:

<input type="checkbox" id="chk+RefNum" [!]onclick="enableTextBox(this)"[/!]>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top