Send form on page load

Discussion in 'JavaScript' started by mman, Jun 26, 2009.

  1. #1
    I am trying to send a form on page load using java, but the only thing I get is a form that isn't submitted and the page is redirected to the action address

    Form code
    <form name="vote" action="http://www.mysite.com/vote.php" method="POST">    
    <input type="submit" name="vote" value="1" >   
    <input type="submit" name="vote" value="Vote1" >   
    </form>
    Code (markup):
    I used <body onLoad="document.vot.submit()"> but it doesn't work
     
    mman, Jun 26, 2009 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Actually, i didnt get your question in the corect sense.
    Can you explain it somewhat clearly.
    why you are using two submit buttons ?
    Also i think , it should be document.forms["vote"].submit();
     
    Unni krishnan, Jun 26, 2009 IP
  3. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How can this form be submitted when the page loads?

    <form name="vote" action="http://www.mysite.com/vote.php" method="POST">    
    <input type="submit" name="vote" value="1" >   
    <input type="submit" name="vote" value="Vote1" >   
    </form>
    Code (markup):
    The form needs some modifications
     
    mman, Jun 26, 2009 IP
  4. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Is this what you are looking for ??
     
    Unni krishnan, Jun 26, 2009 IP
  5. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Doesn't work
     
    mman, Jun 26, 2009 IP
  6. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #6
    the form is wrong? you can't have 2 submits. remove one and it will work.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
    	<title>test</title>
    	
    </head>
    <body>
    	<?=print_r($_POST)?><br />
    	<form name="vote" action="autosubmit.php" method="POST">    
    	<input type="submit" name="vote" value="1" >   
    	
    	</form>	
    	<script type="text/javascript">
    	window.onload = function() {
    		document.forms['vote'].submit();
    		
    	}
    	</script>
    </body>
    </html>
    PHP:
     
    dimitar christoff, Jun 26, 2009 IP
  7. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #7
    May be delete one submit button.
    The php file isn't present in the location.

    Yes this is what happens on submit. The page is redirected to the action parameter and the element values in the form are passed along with them.
    Action specifies where to send the form-data when a form is submitted.
     
    Unni krishnan, Jun 26, 2009 IP
  8. pipisdicelana

    pipisdicelana Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    you must use different name for submit button
     
    pipisdicelana, Jun 27, 2009 IP
  9. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Yes , you can use two submit buttons.
    But have to identify which was pressed.
    You can use the follwing code.

     
    Unni krishnan, Jun 30, 2009 IP
  10. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #10
    its a bad form anyway -> cant all be name="vote", inclusive of the form itself, especially since he does not assign ids...

    when this is not driven by an event such as a mouse click - you are calling the form's submit method and that needs to 'pick' between two the submits?
     
    dimitar christoff, Jun 30, 2009 IP
  11. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #11
    Yes offcourse it is a bad one.

    Just told that its possible.
     
    Unni krishnan, Jun 30, 2009 IP
  12. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #12
    it's possible to have 2 buttons and its possible to determine which one was clicked on by the click event. BUT

    it is NOT possible to use the form .submit() method and get it to decide which button to click instead. does that make sense why the auto submit fails?
     
    dimitar christoff, Jul 1, 2009 IP