Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2004, 07:20 PM   PM User | #1
shaked
New to the CF scene

 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
shaked is an unknown quantity at this point
how do i click a button in a page using javascript?

how do i click a button in a page using javascript?
shaked is offline   Reply With Quote
Old 10-27-2004, 07:36 PM   PM User | #2
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
Heh, hey. welcome to the forum.

you might need to be a little more specific... can you give an example of what you mean, a url to an example, or a more descriptive elaboration?
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 10-27-2004, 07:40 PM   PM User | #3
shaked
New to the CF scene

 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
shaked is an unknown quantity at this point
answer

there is a button in the page
<p><input type="submit" name="button" value="button"></p>
how do i click the button using JAVESCRIPT and not by the mouse when the page is loaded?
shaked is offline   Reply With Quote
Old 10-27-2004, 09:09 PM   PM User | #4
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
so you want this button to be activated when the page is loaded?

i know its possible... i dont offhand know how. it would use either
Code:
window.onload="something"
or
<body onload="something">
maybe something like

Code:
function clickOnLoad()
{
	document.formname.button_name.value = "true";
}

....
<body onload="clickOnLoad()">
formname is the name of your form
button_name is the name of the button

I dont know about the .value = true; part... someone will have to check that for me
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 10-27-2004, 09:11 PM   PM User | #5
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
You want a form to submit all by itself when the page containing the form is loaded? The following should work as long as you've only got one form on the page.

Code:
<body onload="document.forms[0].submit();">
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.
Roy Sinclair is offline   Reply With Quote
Old 10-27-2004, 10:38 PM   PM User | #6
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
and if not would you just add the formname in instead of the 0?

i.e

Code:
<body onload="document.forms[formname].submit();">
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 10-27-2004, 10:39 PM   PM User | #7
hemebond
Senior Coder

 
Join Date: Jul 2004
Location: New Zealand
Posts: 1,315
Thanks: 0
Thanked 2 Times in 2 Posts
hemebond is an unknown quantity at this point
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
	<head>
		<title>46705</title>
	</head>
	<body>
		<input id="btn" type="button" value="press me">
	</body>
	<script type="text/javascript">
		document.getElementById("btn").onclick = document.getElementById("btn").disabled = true;
	</script>
</html>
hemebond is offline   Reply With Quote
Old 10-28-2004, 04:22 AM   PM User | #8
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
errmm... Hemebond, what exactly does that do to help this issue at hand...? from what i get that disables the button once its clicked...

__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 10-28-2004, 05:08 AM   PM User | #9
hemebond
Senior Coder

 
Join Date: Jul 2004
Location: New Zealand
Posts: 1,315
Thanks: 0
Thanked 2 Times in 2 Posts
hemebond is an unknown quantity at this point
The button is disabled because it has been clicked. I've just shown how to click a button using Javascript.

If he just want's to submit a form when the page loads, that's extremely simple; but for anyone looking for a way to click a button using Javascript, there's the solution.
hemebond is offline   Reply With Quote
Old 10-28-2004, 05:17 AM   PM User | #10
fci
Senior Coder

 
Join Date: Aug 2004
Location: Twin Cities
Posts: 1,345
Thanks: 0
Thanked 0 Times in 0 Posts
fci is an unknown quantity at this point
isn't there an obj.click() ? which simulates clicking a button? although it's not speficied in any standard, I am pretty I've seen it in the JS reference for IE and Mozilla/Firefox.

edit: link, http://www.mozilla.org/docs/dom/domr...4.html#1028373
fci is offline   Reply With Quote
Old 10-28-2004, 06:32 AM   PM User | #11
adios
Senior Coder

 
Join Date: Jun 2002
Posts: 1,404
Thanks: 2
Thanked 32 Times in 32 Posts
adios is on a distinguished road
Button.click() is not only not a part of any standard (as msdn would say), it's poorly supported.

Roy S. answered this properly. A button is a UI widget - it allows a user to launch script, or whatever. You're not a user (well, not in this case, anyway). Program it!

Last edited by adios; 10-28-2004 at 06:41 AM..
adios is offline   Reply With Quote
Old 10-28-2004, 01:09 PM   PM User | #12
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
good point Heme, i hadnt seen it that way.
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53 AM.


Advertisement
Log in to turn off these ads.