1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to submit form automatically using javaScript

Discussion in 'JavaScript' started by YIAM, Aug 26, 2007.

  1. #1
    I want to create form which can submit data automatically, without using submit button.

    I need something like this http://www.bontragercgi.com/Automatic_Form_Submission_to_a_CGI_Program.html
    <script type="text/javascript" language="JavaScript"><!--
    document.MyForm.ThisPageURL.value = document.URL;
    var visitortime = new Date();
    document.MyForm.TimeZoneOffset.value = visitortime.getTimezoneOffset();
    document.MyForm.submit();
    //--></script>
    Code (markup):
    
    <form name="MyForm" method="POST" action="/cgi-bin/script.cgi">
    <input type="hidden" name="ThisPageURL" value="">
    <input type="hidden" name="TimeZoneOffset" value="">
    </form>
    
    Code (markup):
    But this doesn't work.

    Thanks in advance for your help.
     
    YIAM, Aug 26, 2007 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Logic Ali, Aug 26, 2007 IP
    YIAM likes this.
  3. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #3
    OOps this was the problem. I was adding the javascript at the top of page between <head> and </head> tags.

    Thanks.
     
    YIAM, Aug 26, 2007 IP
  4. tazogamer

    tazogamer Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Here is a working auto-submit method: when page is loaded, it will the form will be immediately autosubmited (the values can be set with php variables).
    
    <form action="page.php"  method="post">
    <input type="text" name="example1" value="<?php echo $_POST['something1'];?>" />
    <input type="text" name="example2" value="ANOTHER_YOUR_VALUE" />
    <input type="submit" />
    </form>
     
    <SCRIPT LANGUAGE="JavaScript">document.forms[0].submit();</SCRIPT>
    
    Code (markup):
    for example, the $_POST['something1'] value is received from the previous real-user submited Form, and this form can add another input with ANOTHER_YOUR_VALUE.

    _______________________
     
    tazogamer, Jan 24, 2013 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    The thread is 5-1/2 years old. If he hasn't solved it by now, I don't think he cares how to solve it.
     
    Rukbat, Jan 25, 2013 IP