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 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.forms[0].submit(); not working

    Link to site: http://mcgehee.ace-onecomputers.com/test
    if you go there, you can see that after you click "submit" a dialog pops up asking you to click ok/cancel, what i'm trying to do is when you click ok, it submits the form. However, all it does is close the pop up window.

    Why?

    JavaScript:
    Code:
    <script type='text/javascript'>//<![CDATA[ 
    
    
     
    function go_there(){
    	
        $.prompt('<b>DISCLAIMER</b> <span style="font-weight:normal">TEXT WILL GO HERE</span>',{
           buttons: { Ok: true, Cancel: false}, 
           callback: function(e,v,m,f){
              if(v){
    
    				 document.form[email].submit();
    			 
              }else{
    
              }
           }
       });
    
    }
    
    //]]>  
    
    </script>
    HTML Form:
    Code:
    <div class="form-wrapper">
    			<form method="post" action="nlphpmail.php" id="email">
                <input type="hidden" name="subject" id="subject" value="Feedback form" />
    				<fieldset>
    					<div class="formfield">
    						<label class="text title" for="contact_who">Name</label>
    						<input type="text" class="text required" name="contact_who" id="contact_who" value="">
    					</div><!-- /.formfield -->
    					<div class="formfield">
    						<label class="text title" for="contact_sendto">Email address</label>
    						<input type="text" class="text required email" name="contact_sendto" id="contact_sendto" value="">
    					</div><!-- /.formfield -->
    					<div class="formfield">
    						<label class="text title" for="contact_phone">Phone</label>
    						<input type="text" class="text required" name="contact_phone" id="contact_phone" value="">
    					</div><!-- /.formfield -->
    					<div class="formfield">
    						<label class="text title" for="contact_message">Message</label>
    						<textarea name="contact_message" class="required" id="contact_message"></textarea>
    					</div><!-- /.formfield -->
    				</fieldset>
    				<div class="formfield">
      <button class="button" id="submit" value="send" type="button" name="submit" onClick="return go_there();">Send</button>
    				
    </div>
    Last edited by pthornt1; 11-02-2012 at 10:35 PM. Reason: wrong link to site

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    well since you have jQuery loaded already, why not use it?

    Code:
    $('#email').submit()

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried this already, and all it does it close the dialog box and not send the form.

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    What is document.form ?

    Don't call the submit method.

    Use a submit button and an onsubmit event handler.

    If you still think its cool to call submit, then I suggest you warn users without JS that the form is useless.

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Logic Ali View Post
    What is document.form ?

    Don't call the submit method.

    Use a submit button and an onsubmit event handler.

    If you still think its cool to call submit, then I suggest you warn users without JS that the form is useless.

    The code has since changed, instead of document.form[email].submit, i changed it to $('#email').submit(); which still is not working.

    could you give me an example of how i would utilize the submit button and an onsubmit event handler? i'm pretty new to javascript/jquery.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    This is *WRONG*
    Code:
         document.form[email].submit();
    It doesn't even make sense.

    There is no such thing as document.form (unless you actually had <form name="form">).

    And email as used there is a *VARIABLE*, not a name. Since you haven't create a variable of that name, you are, essentially, doing:
    Code:
         document.null[null].submit()
    What you need is:
    Code:
         document.getElementById("email").submit( );
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    For the onsubmit, you would *NOT* be able to use your go_there() function as it exists.

    You could NOT use a callback function, as you would need to return true/false from go_there() directly.

    Stick with what you have.

    But, as LogicAli said, it won't then work if the user has JS disabled.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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