|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Changing html tags with a checkbox
Can someone help, I'm not overly familiar with javascript!! I want to have a field in a table that contains 1 text field if a checbox is checked, and 2 if its not.
I've tried using: [code] function PostFunction() { if (FrmRecipient.chkforces.checked) { FrmRecipient.postcodecell.innerHTML = '<input type="text" name="Postcode" size="25" maxlength=25 value="<%=Asp_Postcode%>" style="font-size:10px; font-family:verdana" onkeypress="return KPress()">'; } } [code] but this tells me that postcodecell in null or not an object?? any suggestions greatly appreciated |
|
#2
|
|||
|
|||
|
You'll have to give some of the HTML also.
I always create a page with all boxes needed, and hides the ones I don't want to see in run-time. E.g. if you have the following HTML: Code:
<input type='checkbox' id='checky' onclick="Show('input2');">
<input type='text' id='input1'>
<input type='text' id='input2'>
The this script will show or hide the input2 box: Code:
function Show(EditID)
{
// Check the DOM
if(document.getElementById)
{
// Get the elements
el_check = document.getElementById('checky');
el_edit = document.getElementById(EditID);
// Check if they were found
if(el_check && el_edit)
{
// Make editbox show when checked
el_edit.style.display = el_check.checked ? '' : none;
}
}
}
Not actually checked it agains errors, but the principle should work. The big advantage is that the user can click the checkbox ON and OFF and ON, and the editbox will toggle with it. The same principle can be used to show/hide a table row (<tr id='row2'>), a span, div etc., which enables you to put some text in front of the input box... |
|
#3
|
|||
|
|||
|
thankyou, that helps a great deal!!!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Changing html tags with a checkbox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|