Link to home
Start Free TrialLog in
Avatar of xiaoyunwu
xiaoyunwuFlag for United States of America

asked on

jquery validate pop window

$(document).ready(function(){
      $('#myForm').validate();
});

I like to use jquery to validate my form, if everything is right, then the result should show in pop up window, validation is not passed, for example, some required field is empty, then, I do not want pop up to come up. Right now, when form is validated, then everything works fine. But if form is invalidated, then, error message shows, but an empty pop up window comes up, I do not want the pop up to comes up until the form is validated. How can I do that? Thanks.

function popupform(form) {
var windowname="newWin";
window.open('', windowname, 'height=75,width=80, scrollbars=1');
form.target = windowname;
}

<form method="post" onsubmit="popupform(this)" id="myForm">
....
</form>
Avatar of Rob
Rob
Flag of Australia image

you could just use the jquery dialog

http://jqueryui.com/demos/dialog/#modal-confirmation


function popupform(form) {
$( "#myform" ).dialog( "destroy" );
	
		$( "#myform" ).dialog({
			height: 140,
			modal: true
		});
}

Open in new window

You can first check/validate your form (better way in another function and return true or false depending upon validation result). then check this return value and depending upon this value show popup window/dialog.

If validation function returns false, dont open popup.
His code is already validating the form. It won't submit unless it validates
Avatar of xiaoyunwu

ASKER

>> tagit: you could just use the jquery dialog

Dialog is not working.
When for is validated it pop up for a few seconds, then close by itself and go to my result page in the same window.
When form is not validated, it pop up the same form again in the dialog, and let me enter info there, then stay there for a few seconds, close by itself and go to my result page in the same window.
I want my result page in the pop up window instead.
>>mroonal:
>>You can first check/validate your form (better way in another function and return true or false >>depending upon validation result). then check this return value and depending upon this value show >>popup window/dialog.

Since I'm using jquery  $('#myForm').validate(); to validate the form, I guess I do not want to write my own code to do the validation to return true or false, if so, I can use your solution.

I want to see if  $('#myForm').validate(); will return true or false or something like that so that I do not have to write my own validation code.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial