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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript to auto click submit button

    I'm quite new at JavaScript, anyway I'm trying to use it to write code to auto click the submit button in a web page. Here's my code:


    <html>
    <head>
    <script LANGUAGE="JavaScript">
    var m_alert = "2";
    var m_type = "top";
    var m_mode = "normal";
    var m_xmlpage = "http://192.168.1.10/topline.xml";
    var m_method = "get";
    var m_ap = "";

    setTimeout("document.xmlform.submit()",2000); //After loading the page, wait 2 secs then submit form

    function PushMsg() {

    xmlform.action = "http://192.168.1.11"; //After hitting submit button, it will go to this url...

    m_ap = '<\?xml version="1.0"?>\n'+
    '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"\n'+
    '"http://www.wapforum.org/DTD/wml13.dtd">\n'+
    '<Push alert= "'+m_alert+'" type="'+m_type+'" mode="'+m_mode+'">\n'+
    '<go href= "'+m_xmlpage+'" method = "'+m_method+'">\n'+
    '</go>\n'+
    '</Push>\n\r';

    document.forms[0].XMLData.value = m_ap; //...and also send these data to the target url
    }
    </script>
    </head>

    <body>

    <form name="xmlform" method="POST" onSubmit="return PushMsg()">
    <input type="hidden" name="XMLData">
    <input type="submit" value="Submit" name="B1">
    </form>

    </body>
    </html>

    Well, I use this page to work with some other pages. This page will be called at the specific time, for example at 9am, 12pm and 5pm the other php page will automatically call this page, then hit submit button in order to send the hidden data in a form tag (<input type="hidden" name="XMLData">) to the target url.

    The problem is, currently it can automatically submit the form, but it doesn't do the onSubmit="return PushMsg()" part, so the PushMsg() is not called to work. Now, instead of going to the target url (http://192.168.1.11) after submitting the form, it just refreshes the same page every 2 secs. However, the code works if I click the submit button myself.

    Is there any way to correct the problem?
    Last edited by wizmay; 05-26-2006 at 04:57 AM.

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this.
    Code:
    if(PushMsg()) document.forms[0].submit();
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't work.

    I think if(PushMsg()) document.forms[0].submit(); will submit the form after running the PushMsg() function.

    But here's what I want the code to do:

    1.) Submit the form and it should call the PushMsg() to run. (at <form name="xmlform" method="POST" onSubmit="return PushMsg()">)

    2.) The PushMsg() will assign the target url and the data to XMLData. (at line xmlform.action = "http://192.168.1.11"; and document.forms[0].XMLData.value = m_ap;)

    3.) Then the XMLData will be used at the hidden field in the form. (at <input type="hidden" name="XMLData">)

    4.) Hit the submit button to send the forn with the data in a hidden field.


    Is that possible for JavaScript?

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why dont you have the form post to another page with the XMLDATA intact, not process it and then store all the data in fields on that page. From thier you can have it submit to another page with that data.

    form ---> submit page ---> process without XMLDATA ---> store data in identical fields with XMLDATA ---> submit page ---> second process form.

  • #5
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's okay. I've got it solved by inserting this in the body tag:

    <body onLoad="PushMsg(); document.xmlform.submit()">
    Thanx you guys for your help!


  •  

    Posting Permissions

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