...

View Full Version : document.forms[0].submit(); not working



pthornt1
11-02-2012, 08:52 PM
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:

<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:

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

DanInMa
11-02-2012, 08:54 PM
well since you have jQuery loaded already, why not use it?


$('#email').submit()

pthornt1
11-02-2012, 09:10 PM
I have tried this already, and all it does it close the dialog box and not send the form.

Logic Ali
11-02-2012, 09:30 PM
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.

pthornt1
11-02-2012, 09:34 PM
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.

Old Pedant
11-02-2012, 09:35 PM
This is *WRONG*


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:


document.null[null].submit()


What you need is:


document.getElementById("email").submit( );

Old Pedant
11-02-2012, 09:39 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum