Reaching component on page, not on form

S

Sonnich

Hi!

I just want a single button on a page (without a form) to be disabled
using JS. My problem is to reach the components/elements on the page.

Like this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function stopuseraction()
{
alert("test");
document.button1.disabled=true; // something is wrong here.
}
//-->
</SCRIPT>
</head>
<body>
<input type="button" name="button1" value="Yo man!"
onClick="stopuseraction(); ">
</body>
</html>
 
L

Lee

Sonnich said:
Hi!

I just want a single button on a page (without a form) to be disabled
using JS. My problem is to reach the components/elements on the page.

Like this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function stopuseraction()
{
alert("test");
document.button1.disabled=true; // something is wrong here.
}
//-->
</SCRIPT>
</head>
<body>
<input type="button" name="button1" value="Yo man!"
onClick="stopuseraction(); ">
</body>
</html>

That's not your only problem. You need to find a book or web site that was
written in the past couple of years:

<html>
<head>
<script type="text/javascript">
function stopuseraction()
{
alert("test");
document.getElementById("button1").disabled=true;
}
</script>
</head>
<body>
<button id="button1" onclick="stopuseraction()">yo man!</button>
</body>
</html>


--
 
S

Sonnich

That's not your only problem. You need to find a book or web site that was
written in the past couple of years:

yep, I am not that much into JS, more to PHP :)
The difference is that there is www.php.net, where I can find all the
help I need. I could use a similar place for JS.
Though, I am not 100% sure of what you mean here.

BR
S
 
S

Sonnich

Sonnichwrote:

function stopuseraction (control)


control.disabled = true;
}


<input onclick="stopuseraction(this);" ...>

Yep, I am aware of that, but say I have a number of items to work
with. The other solution works fine.

BR
S
 
J

John Postlethwait

Yep, I am aware of that, but say I have a number of items to work
with. The other solution works fine.

BR
S

Form elements are not methods of the document object, so what you were
trying to do would never work outside of a form object (IE:
document.forms['myForm'].elements['myButton'];)

You can also use document.getElementById("html_id_of_button") to get
the object... All object methods will work on this just as if you used
the longer DOM methods to get it. (document.forms.etc...) Just
remember to set the HTML id attribute on the object you want to find.

I would recommend using Sonnich's solution as it is the most
extensible.
 
J

John Postlethwait

Yep, I am aware of that, but say I have a number of items to wor
with. The other solution works fine.

BR
S

Sorry, the formatting of this post confused me a bit, I believe I
referenced Martin Honnen's solution...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top