0

Possible Duplicate:
submit is not a function in javascript
How to submit form using JS

I have a contact form, and what is supposed to happen in the user clicks submit, a dialog box opens, they click OK, and then the form submits. However, when you click OK, it just closes the dialog box and DOES NOT submit the form. You can test the code by going here.

Javascript/jQuery: //

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){

                 $('#email').submit()

          }else{

          }
       }
   });

}


//]]>  

</script>

HTML: //

<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="go_there();">Send</button>
                </div>
                </form>
Community
  • 1
  • 1
Trisha
  • 539
  • 3
  • 10
  • 30
  • 1
    similiar http://stackoverflow.com/questions/12876293/how-to-submit-form-using-js/12876339 the submit button `#submit` overwrites the submit function. – Musa Nov 02 '12 at 20:30
  • @Trisha I think @Musa's suggestion via that post is to change the `name` and `id` of your submit button. – Kevin Boucher Nov 02 '12 at 20:46
  • @KevinBoucher is correct do not have any form elements with name or id `submit` if you intend to submit it via JavaScript with the submit function. – Musa Nov 02 '12 at 20:48
  • Thanks, that did solve one issue.. now when it submits the form, it directs to the actual nlphpmail.php and loads the error "this page cannot be accessed directly".. @Musa – Trisha Nov 02 '12 at 20:53
  • There is a `$.prompt` not defined error – Musa Nov 02 '12 at 20:59
  • @Musa The creater of the Impromptu plugin is the one who advised me to code it this way, so I'm not sure why it is giving a not defined error? – Trisha Nov 02 '12 at 21:02

1 Answers1

0

Have the "Submit" button be an input type="button" rather than input type="submit". Add an onclick to the "OK" button that actually submits the form. Also, as Musa mentioned, don't set anything with an id of "submit".

Ben Barden
  • 2,001
  • 2
  • 20
  • 28
  • Ben - this helped, however - now when OK is clicked, it loads the nlphpmail.php, but does not send the form. It goes to the form error "cannot be accessed directly" [check here](http://mcgehee.ace-onecomputers.com/test) – Trisha Nov 02 '12 at 20:48
  • "cannot be accessed directly" appears to be an issue with the destination page, rather than the page we're talking about. Are you sure you intended to link there, as opposed to some derived address? Also, you might want to check cross-browser compatibility. I'm seeing two different misbehaviors in Chrome and IE. – Ben Barden Nov 02 '12 at 20:56
  • Ben, it is supposed to direct to that page. if needed, I can post the PHP code for that page if it will help find the issue. As for the misbehaviors, what are they? – Trisha Nov 02 '12 at 21:01
  • jsfiddle with nlphpmail.php code [here](http://jsfiddle.net/x8Hxj/1/) – Trisha Nov 02 '12 at 21:05
  • misbehaviors: IE complains repeatedly about JQuery not being defined. Chrome leaves the default grey text in place when you start typing, and just ahs you type under it. As far as the other goes, test for yourself - can you get to the nlphpmail.php page directly by typing the address into the addressbar? – Ben Barden Nov 02 '12 at 21:10
  • Also, I note that nothing shows up on the "result" page of your fiddle. – Ben Barden Nov 02 '12 at 21:13
  • no, typing in an addressbar goes to the cannot be access directly error. however, if it were just a regular form directing to nlphpmail.php, it would submit the form (example [here](http://mcgehee.ace-onecomputers.com/form/)) as for the fiddle - wouldn't that be because its PHP and not JS? – Trisha Nov 02 '12 at 21:20
  • if it cannot be resolved, maybe trying a different contact form would help i wonder.. – Trisha Nov 02 '12 at 21:22