Click to See Complete Forum and Search --> : tag name
tiger66
07-04-2003, 09:34 AM
Hello I am trying to disable a field by its name
eg
document.myForm.fieldName.disabled = true;
However, it doesn't get the name
where did i do wrong?
Thanks
chrismartz
07-04-2003, 10:37 AM
check this page out
http://www.codetoad.com/javascript/enable_disable_form_element.asp
Khalid Ali
07-04-2003, 10:58 AM
2 possibilities..
either formName is not a valid name
or
fieldName is not a valid name
please see if they are correct and beware that JavaScript is case sensitive...
Originally posted by tiger66
Hello I am trying to disable a field by its name
eg
document.myForm.fieldName.disabled = true;
However, it doesn't get the name
where did i do wrong?
Try some of these examples, if your question hasn't already been answered.
<!-- Example One: -->
<script type="text/javascript">
<!--
var elem;
function disableElem(elem){elem.disabled=true;}
function enableElem(elem){elem.disabled=false;}
//-->
</script>
</head><body>
<form action="" name="myForm"><div>
<input type="button" onMouseOver="disableElem(this);" onMouseOut="enableElem(this);" value="Try to Click Me!">
</div></form>
</body></html>
<!-- Example Two: -->
<script type="text/javascript">
<!--
function disabledButton(){
document.myForm.elements[0].disabled=true;
}
function enabledButton(){
document.myForm.elements[0].disabled=false;
}
//-->
</script></head>
<body>
<form action="" name="myForm"><div>
<input type="button" onMouseOver="disabledButton();" onMouseOut="enabledButton();" value="Try to Click Me!">
</div></form>
</body></html>
<!-- Example Three: -->
<script type="text/javascript">
<!--
function disableButton(){
document.myForm.myButton.disabled=true;
}
function enableButton(){
document.myForm.myButton.disabled=false;
}
//-->
</script></head>
<body>
<form action="" name="myForm"><div>
<input type="button" onMouseOver="disableButton();" onMouseOut="enableButton();" value="Try to Click Me!">
</div></form>
</body></html>
[J]ona
tiger66
07-05-2003, 12:13 AM
I've noticed that my way of disabling can work on most of the tags except radio button
for example
javascript
function disable()
{
document.myForm.a.disabled = true
}
<body onLoad="disable()">
<form name="myForm">
<input type="radio" name="a" value="hi" checked>
<input type="radio" name="a" value="hello">
</form>
it only disables the first radio button. Although the second radio button doesn't get disabled, it doesn't work
When I try to enable the disabled radio button like
document.myForm.a.disabled = false
non of them get enabled
So I was wondering is there a way just for disabling and enabling the radio buttons?
Thanks
tiger66
07-05-2003, 08:41 AM
I can disable/enable the radio buttons if I treat their names as an array:)
for example if I have two radio buttons
document.myForm.myRadio[0].disabled = true/false;
document.myForm.myRadio[1].disabled = true/false;
Khalid Ali
07-05-2003, 11:57 AM
Originally posted by tiger66
I can disable/enable the radio buttons if I treat their names as an array:)
In your first post you did not mention about radio buttons,you always should name your radio button as an array..:D
<form name="form_one">
<input type="radio" name="r1">
<input type="radio" name="r1">
</form>
<script>
for(i=0;i<document.form_one.elements.length;i++){
if(document.form_one.elements[i].type="radio"){
document.form_one.elements[0].disabled=true
}
}
</script>
tiger66
07-05-2003, 05:22 PM
Hi
I am just wondering does all the innerHTML tags also get disabled if I use a for loop to loop through the entire form?
Thanks
tiger66
07-05-2003, 05:24 PM
I mean disabling the tags while looping through the entire form. Does innerHTML tags also get disabled?
innerHTML is not a tag, more of a method
tiger66
07-05-2003, 05:50 PM
sorry, I mean if I have innerHTML outputting some of my form tags, are those tags also get disabled?
Originally posted by Mr J
innerHTML is not a tag, more of a method
'Tis a property. ;)
[J]ona
Yep something like that
:D