/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@chrismartzJul 04.2003 — check this page out

[URL=http://www.codetoad.com/javascript/enable_disable_form_element.asp]http://www.codetoad.com/javascript/enable_disable_form_element.asp[/URL]
Copy linkTweet thisAlerts:
@Khalid_AliJul 04.2003 — 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...
Copy linkTweet thisAlerts:
@JonaJul 04.2003 — [i]Originally posted by tiger66 [/i]

[B]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?[/b]
[/QUOTE]


[font=arial][color=maroon]Try some of these examples, if your question hasn't already been answered. [/color][/font]

[font=monospace]

<!-- 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>

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@tiger66authorJul 05.2003 — 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
Copy linkTweet thisAlerts:
@tiger66authorJul 05.2003 — 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;
Copy linkTweet thisAlerts:
@Khalid_AliJul 05.2003 — [i]Originally posted by tiger66 [/i]

[B]I can disable/enable the radio buttons if I treat their names as an array?



[/B]
[/QUOTE]

In your first post you did not mention about radio buttons,you always should name your radio button as an array..?
Copy linkTweet thisAlerts:
@Mr_JJul 05.2003 — [SIZE=1]<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>
[/SIZE]
Copy linkTweet thisAlerts:
@tiger66authorJul 05.2003 — 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
Copy linkTweet thisAlerts:
@tiger66authorJul 05.2003 — I mean disabling the tags while looping through the entire form. Does innerHTML tags also get disabled?
Copy linkTweet thisAlerts:
@Mr_JJul 05.2003 — innerHTML is not a tag, more of a method
Copy linkTweet thisAlerts:
@tiger66authorJul 05.2003 — sorry, I mean if I have innerHTML outputting some of my form tags, are those tags also get disabled?
Copy linkTweet thisAlerts:
@JonaJul 05.2003 — [i]Originally posted by Mr J [/i]

[B]innerHTML is not a tag, more of a method [/B][/QUOTE]


[font=arial][color=maroon]'Tis a property. ?[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@Mr_JJul 06.2003 — Yep something like that


?
×

Success!

Help @tiger66 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...