473,819 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing a function only after success validation

2 New Member
Im having a minor, simple problem. Basicly i have two different scripts they both work separately and together but just that both executes at the same time.

On my html page i have a form, one of the functions are that you can fill in the fields and when you press on a button you go to a new page, were all filled fields are shown.

Now i want to validate the form before i pass on the filled information to the "next page".

But right now when you click on the button, you get your form validated as normal and then you just get sent to the "next page" even if you fail to meet up the req.

<input name="submit" value="submit" onClick="compil e(); validate(this.f orm); return document.formSu bmit;" type="button">
JS code:

function validate(form){
var error = "";
//for each form element
for(var i=0; i<form.length; i++){
var element = form[i];
//if required
if(element.getA ttribute("requi red") == "yes"){
//if form element if empty
if(!valid(eleme nt.value,elemen t.getAttribute( "validate"),ele ment))
error += element.getAttr ibute("message" ) + "\r\n";
}
}
if(error != ""){
alert(error);
document.formSu bmit = false;
}
else
document.formSu bmit = true;
}

function valid(value,typ e,element){
if(value == "")
return false;

switch(type){
case "int":
if(isNaN(parseI nt(value)))
return false;
break;
case "float":
if(isNaN(parseF loat(value)))
return false;
break;
case "email":
var p = value.indexOf(' @');
if(p<1 || p==(value.lengt h-1))
return false;
break;
case "checked":
if(!element.che cked)
return false;
break;
default://string
break;
}
return true;
}

//gather information
//pass on to "kontakta_print .html".
function compile() {
var falt = escape(document .form1.fornamn. value) + "&" +
escape(document .form1.efternam n.value) + "&" +
escape(document .form1.gatuadre ss.value) + "&" +
escape(document .form1.postnumm er.value) + "&" +
escape(document .form1.postort. value) + "&" +
escape(document .form1.tfnnumme r.value) + "&" +
escape(document .form1.epost.va lue) + "&" +
escape(document .form1.meddelan de.value);
location.href = "kontakta_print .html?" + falt;
}

//get information from previous form
function getInfo() {
var find = location.search ;
var get = find.substring( 1);
var lista = get.split("&");
lista[0] = unescape(lista[0]);
return lista;
}

//funtion for printout
function skrivUt() {
var skriv = getInfo();
document.write( "<p><b>F&ouml;r namn: </b>" + skriv[0] + "<p>");
document.write( "<p><b>Efternam n: </b>" + skriv[1] + "<p>");
document.write( "<p><b>Adre ss: </b>" + skriv[2] + "<p>");
document.write( "<p><b>Postnumm er: </b>" + skriv[3] + "<p>");
document.write( "<p><b>Post ort: </b>" + skriv[4] + "<p>");
document.write( "<p><b>Telefonn ummer: </b>" + skriv[5] + "<p>");
document.write( "<p><b>E-post: </b>" + skriv[6] + "<p>");
for (var i=0; i<skriv.length ; i++)
document.write( "<input type='hidden' name='input'" + i + "' value='" +skriv[i] + "' />");
}
Aug 7 '06 #1
2 10924
cryme
2 New Member
i fixed it :) just learn how to call a function
Aug 7 '06 #2
aspcoder
1 New Member
Im having a minor, simple problem. Basicly i have two different scripts they both work separately and together but just that both executes at the same time.

On my html page i have a form, one of the functions are that you can fill in the fields and when you press on a button you go to a new page, were all filled fields are shown.

Now i want to validate the form before i pass on the filled information to the "next page".

But right now when you click on the button, you get your form validated as normal and then you just get sent to the "next page" even if you fail to meet up the req.



JS code:
Had the same problem. I solved it by checking the name on the inputboxes. If the name in your script and the name on the inputboxes in your form is different, the script will show the error messages on the ones that are correct and the send you directly to your "next" page. If all names are correct it will work perfectly.
Oct 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1808
by: Victor Ng | last post by:
Is there a way to preserve the argspec of a function after wrapping it in a closure? I'm looking for a general way to say "wrap function F in a closure", such that inspect.getargspec on the closure would return the same (args, varargs, varkw, defaults) tuple ass the enclosed function. The typical code I'm using is something like this: def wrapFunc(func):
2
9786
by: Tony Liu | last post by:
Hi, I want to get the name of the calling function of an executing function, I use the StackTrace class to do this and it seems working. However, does anyone think that there any side effect towards this approach such as how would it works in multi-thread. Thanks Tony
2
4931
by: Cheng Wei-Chao | last post by:
hi: i have a button, when i click it i want to store data to database and open a new window in general we use java script to open new window but how to call java script function after i executived the server side code thank you!
1
1833
by: John DeSoi | last post by:
Is there a mechanism to execute a function after the user connects to the database? I would like to set the schema path based on the user's group membership. It would also be nice to log to a table on connect/disconnect. Thanks, John DeSoi, Ph.D.
3
2216
by: Mae Lim | last post by:
Hi All, I've a problem here, I want to trigger a javascript function after binding the ListBox control. Basically the javascript will remove the duplicates records after recordset is bind in the ListBox control automatically without users onclick/onchange the ListBox. I don't want to distinct the records in the SQL query, because I have other usage for those duplicates records.
5
2487
by: reycri | last post by:
Hi, I need to be able to do this: var func = new Function("var me = <selfRef>; alert(me.params);"); func.params = "This is a test parameter"; window.setTimeout(func, 500); Basically, I need to add properties to a function object and access them within the function when it is executing. Therefore, I need to be
0
599
by: kloppie | last post by:
Hi there, i want to update a Label after a succesfull Timer Tick, and the time to use is the users local time. Therefore I want to execute a Javascript function after the Tick has occured - anybody knows how to do that? .. Martin Klopp Jensen
4
2309
by: sultanwadood | last post by:
Hi all. I need to know how to restore or roll back to built-in function after overriding like following example. String.prototype.substr= function() { return "";} Now I want to use the one already built-in. I shall be very thankful if some one could help me. Sultan Wadood
3
9600
by: neovantage | last post by:
Hi Experts, I have create a jQuery ui function which delete product from the shopping list. After receiving a jQuery Ajax response i want to bind the same function which load on page load. How can i bind the same function after receiving the Response. Here is my JavaScript Code $( ".rData" ).click(function() { $( "#dialog-confirm:ui-dialog" ).dialog( "destroy" ); myLink = $(this).attr("href"); $.urlParam = function(name){...
0
9748
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10703
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9248
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5590
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3917
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3046
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.