Solved

jquery validate pop window

Posted on 2011-09-02
6
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Rob
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 43

Expert Comment

by:Rob
ID: 36485811
His code is already validating the form. It won't submit unless it validates
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 43

Accepted Solution

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

756 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