Solved

jquery validate pop window

Posted on 2011-09-02
6
322 Views
Last Modified: 2012-05-12
$(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>
0
Comment
Question by:xiaoyunwu
  • 3
  • 2
6 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 36476763
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

0
 
LVL 22

Expert Comment

by:Mrunal
ID: 36482814
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.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 36485811
His code is already validating the form. It won't submit unless it validates
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:xiaoyunwu
ID: 36489080
>> 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.
0
 

Author Comment

by:xiaoyunwu
ID: 36489113
>>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.
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 36493496
You should use the submitHandler to replace the forms submit

eg

$(".selector").validate({
   submitHandler: function(form) {
       // do other stuff for a valid form
   	form.submit();
   }
})

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now