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
Solved

jquery validate pop window

Posted on 2011-09-02
6
329 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 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
If condition on Html with Asp 11 27
Jquery 2 23
Html CheckBox obtain Its Value 5 27
multiple selects 23 48
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

856 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