By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,362 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,362 IT Pros & Developers. It's quick & easy.

Reaching component on page, not on form

P: n/a
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>

Jan 31 '07 #1
Share this Question
Share on Google+
6 Replies

P: n/a
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>
--

Jan 31 '07 #2

P: n/a
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

Jan 31 '07 #3

P: n/a
Sonnich wrote:
function stopuseraction()
function stopuseraction (control)
{
alert("test");
control.disabled = true;
}

<input type="button" name="button1" value="Yo man!"
onClick="stopuseraction(); ">
<input onclick="stopuseraction(this);" ...>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 31 '07 #4

P: n/a
On Jan 31, 7:56 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Sonnichwrote:
function stopuseraction()

function stopuseraction (control)
{
alert("test");

control.disabled = true;
}
<input type="button" name="button1" value="Yo man!"
onClick="stopuseraction(); ">

<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

Jan 31 '07 #5

P: n/a
On Jan 31, 10:24 am, "Sonnich" <sonnich.jen...@elektrobit.comwrote:
On Jan 31, 7:56 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Sonnichwrote:
function stopuseraction()
function stopuseraction (control)
{
alert("test");
control.disabled = true;
}
<input type="button" name="button1" value="Yo man!"
onClick="stopuseraction(); ">
<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
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.

Feb 1 '07 #6

P: n/a
On Jan 31, 10:24 am, "Sonnich" <sonnich.jen...@elektrobit.comwrote:
On Jan 31, 7:56 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Sonnichwrote:
function stopuseraction()
function stopuseraction (control)
{
alert("test");
control.disabled = true;
}
<input type="button" name="button1" value="Yo man!"
onClick="stopuseraction(); ">
<input onclick="stopuseraction(this);" ...>

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

Feb 1 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.