Solved

jquery validate pop window

Posted on 2011-09-02
6
332 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
make control visible based off other control value 7 42
Two decimal 5 41
Why is my $_POST not going to results page 10 65
hide and show spans from dropdown selection 3 34
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

739 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