I'm trying to dynamically add an input box element directly after an input checkbox, onclick of that checkbox. I am able to create the input box dynamically but since the checkbox I'm trying to add after is not a parent I can't append a child to it. How can I get around this? Which function do I use?
Textbox is what I want to add/remove dynamically and it can be next to any number of checkboxes depending on which are clicked by the user. Then parent is the span, correct? But what would node and referenceNode be?
Thanks
Here's another one, although Fang's is more unobtrusive:
The script:
Code:
function showDiv( id ) {
document.all.textBox01.style.visibility = 'hidden';
document.all.textBox02.style.visibility = 'hidden';
document.all.textBox01.value = '';
document.all.textBox02.value = '';
document.all[ id ].style.visibility = 'visible';
document.all[ id ].focus();
}
Place in the body:
Code:
Add your e-mail address here: <input type=radio name=radioBtn onClick="showDiv( 'textBox01' );">
<input type=text name=textBox01 size=30 style="visibility:hidden">
<br>
Give us your FAX number: <input type=radio name=radioBtn onClick="showDiv( 'textBox02' );">
<input type=text name=textBox02 size=20 style="visibility:hidden">
Greetings!
I used this code in a registration form and it works fine in Safari and Explorer on both the Mac and PC but it won't work in Firefox. I know the example does so I was wondering what I may have missed or if there could be a conflict with other scripts in my php page?
This is my code in the head:
<script language="JavaScript">
function showDiv( id ) {
document.all.textBox01.style.visibility = 'hidden';
document.all.textBox01.value = '';
document.all[ id ].style.visibility = 'visible';
document.all[ id ].focus();
-->
</script>}
And the code in the body. I added an onBlur line that works great too - but removing it does not make it work in Firefox.
<td>Click here to enter special code: <input type=radio id=RegistrationFee name=RegistrationFee onClick="showDiv( 'textBox01' );">
<input type=text name=textBox01 size=5 style="visibility:hidden" onBlur="form.Amount.value = value" /> </td>
I was wondering if anyone may have some thoughts. I've been trying different things but can't find the error.
I used this code in a registration form and it works fine in Safari and Explorer on both the Mac and PC but it won't work in Firefox. I know the example does so I was wondering what I may have missed or if there could be a conflict with other scripts in my php page?
This is my code in the head:
<script language="JavaScript">
function showDiv( id ) {
document.all.textBox01.style.visibility = 'hidden';
document.all.textBox01.value = '';
document.all[ id ].style.visibility = 'visible';
document.all[ id ].focus();
-->
</script>}
And the code in the body. I added an onBlur line that works great too - but removing it does not make it work in Firefox.
<td>Click here to enter special code: <input type=radio id=RegistrationFee name=RegistrationFee onClick="showDiv( 'textBox01' );">
<input type=text name=textBox01 size=5 style="visibility:hidden" onBlur="form.Amount.value = value" /> </td>
I was wondering if anyone may have some thoughts. I've been trying different things but can't find the error.
Thanks so much!
Noticed the } was out of place but it didn't help putting it back in.
The code works great...the one from Fang, however, I need it to be more specific. I have several 'input' tags on the page and this allows the text box to show on every one of them. I want it to be on the ones that are only referring to checkboxes. I've tried everything I can think of and can't get it to refer just to checkboxes. Any suggestions?
function addElement() {
var aInput=document.getElementById('myspan').getElementsByTagName('input');Need this to refer to Checkboxes only
for(var i=0; i<aInput.length; i++) {
aInput[i].onclick=new Function('addDelete(this)');
}
}
function addDelete(obj) {
var parentSpan=document.getElementById('myspan');
if(obj.nextSibling.nodeName!='INPUT') { // add
var oInputText=document.createElement('input');
oInputText.setAttribute('type', 'textarea');
parentSpan.insertBefore(oInputText, obj.nextSibling);
}
else { // delete
parentSpan.removeChild(obj.nextSibling);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
function addElement() {
var aInput=document.getElementById('myspan').getElementsByTagName('input');Need this to refer to Checkboxes only
for(var i=0; i<aInput.length; i++) {
if(aInput[i].getAttribute('type')=='checkbox') {aInput[i].onclick=new Function('addDelete(this)');}
}
}
At least 98% of internet users' DNA is identical to that of chimpanzees
Bookmarks