www.webdeveloper.com
Results 1 to 5 of 5

Thread: How click submit button auto in place of onclick()

  1. #1
    Join Date
    Apr 2010
    Posts
    18

    Post How click submit button auto in place of onclick()

    i made a java script program that save values from text field to cookies and recall it in another text field with recall button.

    but i m trying to make auto means without any submit button its save and recall after few seconds.
    or make the button to click auto...

    is it possible?

    my code are here:

    Code:
     
    <html>
    
    <head>
    
    <script type = "text/javascript">
    
    function createCookie(name,value,days) {
    if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (10000));
    var expires = "; expires = "+ date.toGMTString();
    }
    else{var expires = ""}
    document.cookie = name + "=" + value + expires + "; path=/";      // available throughout the directory
    }
    
    
    
    
    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
    var cb = ca[i];
    while (cb.charAt(0)==' ') {cb = cb.substring(1,cb.length)}
    if (cb.indexOf(nameEQ) == 0) {
    retval = cb.substring(nameEQ.length,cb.length);
    document.getElementById("txtInput1").value =  retval;
    return retval;
    }
    }
    return null;  // no display if cookie not found
    }
    
    function eraseCookie(name) {
    createCookie(name,"",-1);  // set cookie to expire on previous day
    }
    
    
    </script>
    <body>
    
    <input type = "text" id = "txtInput" value="12">
    <input type = "text" id = "txtInput1">
    
    <input type = "button" value = "Save" onclick="createCookie('mycookie',document.getElementById('txtInput').value, 10)">
    <input type = "button" value = "Recall" onclick = "readCookie('mycookie')">
    
    </body>
    </html>
    i think i need to make change here:

    Code:
    <input type = "button" value = "Save" onclick="createCookie('mycookie',document.getElementById('txtInput').value, 10)">
    <input type = "button" value = "Recall" onclick = "readCookie('mycookie')">
    or need another program or set timeinterval in createcookie() and readcookie() function...is it?

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434
    AFAIK, you cannot cause JS to execute an onclick event. User should be doing this when they want.
    I would not like my computer to override my choices with an automatic onclick event that I did not instigate.

    Also, to save the same information over and over to a cookie every few minutes seems like a waste of computation time.
    What is is that is so important to monitor?

  3. #3
    Join Date
    Apr 2010
    Posts
    18

    Post

    cause this is my experimental code ...after success of its saving and recalling data auto in cookie, i'll apply it in my factory production floor.

    where inputs coming from PLC (Programmable logic control) and store data in one network server, from server to PC in IE its showing the values which is changing after every 2 seconds. i want to modify this page to save some specific value and call it after few sec where existing value already change and finally compare both values. i cant change the server program that why i need to change the page where it showing in IE.

    any other way to save single value for few seconds and recall and again save/recall continuously?????? any help will be highly appreciable.....

    my target is like it:
    input=3 show=3
    input=4 show=4 (compare max existing show 3 and new input 4 )
    input=6 show=6 (compare max existing show 4 and new input 6 )
    input=3 show=6 (compare max existing show 6 and new input 3 )
    input=2 show=6 (compare max existing show 6 and new input 2 )

    i want to save show data for few sec in cookie and recall it after existing value change....

    thanks

  4. #4
    Join Date
    Oct 2012
    Posts
    39
    Try this.
    if(PushMsg()) document.forms[0].submit();

  5. #5
    Join Date
    Apr 2010
    Posts
    18

    Post

    i cant understand where i need to add it , in main program after each function end or in onclick selection.
    pusgmsg() means what..actually i m not so expert ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles