Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do i click a button in a page using javascript?

    how do i click a button in a page using javascript?

  • #2
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)

  • #3
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #4
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)

  • #7
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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>

  • #8
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)

  • #9
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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.

  • #10
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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 07:41 AM.

  • #12
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •