I am trying to call more than one function starting with onclick in a form to work in all browsers.
In the form, this calls only function_1: -
<input type="submit" value="thevalue" name="goodname" onclick="return function_1(this.form);function_2(this.form);" />
-
So I tried only function_1 for the onclick, and put this in a .js file, but it also does not call function_2: -
function function_1(health)
-
{
-
if(health.phone.value=="")
-
{
-
alert("Please enter your home telephone number.\n");
-
return false;
-
}
-
return true;
-
function_2();
-
}
-
-
function function_2(health)
-
{
-
-
if(health.first_name.value.length<2)
-
{
-
alert("Please enter your first name.\n");
-
return false;
-
}
-
return true;
-
}
-
In both cases, the first function works, but not the second, and the Firefox Error Console does not return an error.
So I tried this in the form, but it produces the error "health has no properties": -
<input type="submit" value="thevalue" name="goodname" onclick="return callThem(this.form);" />
-
with this in the .js file: -
function callThem()
-
{
-
function_1();
-
function_2();
-
}
-
-
function function_1(health)
-
{
-
if(health.phone.value=="")
-
{
-
alert("Please enter your home telephone number.\n");
-
return false;
-
}
-
return true;
-
}
-
-
function function_2(health)
-
{
-
-
if(health.first_name.value.length<2)
-
{
-
alert("Please enter your first name.\n");
-
return false;
-
}
-
return true;
-
}
-
How do I call function_2?
3 3221 gits 5,390
Recognized Expert Moderator Expert
just write a 'wrapper'-function func_3 like this: - function func_3(health) {
-
var val = true;
-
-
val = function_1(health);
-
-
// in case function_1 returns true we call function_2
-
if (val) {
-
val = function_2(health);
-
}
-
-
return val;
-
}
now just call func_3 in your onclick :)
kind regards
I tried that but now when the alert window for function_1 is clicked, the form goes to the "action=" without any entry needing to be made in the form. -
function func_3(health)
-
{
-
var val = true;
-
val = function_1(health);
-
//in case function_1 returns true, we call function_2
-
if(val)
-
{
-
val = function_2(health);
-
}
-
return val;
-
}
-
-
function function_1(health)
-
{
-
if(health.phone.value=="")
-
{
-
alert("Please enter your home telephone number.\n");
-
return false;
-
}
-
return true;
-
}
-
-
function function_2(health)
-
{
-
if(health.first_name.value.length<2)
-
{
-
alert("Please enter your first name.\n");
-
return false;
-
}
-
return true;
-
}
-
There is currently no other code in this .js file.
Still puzzled.
gits 5,390
Recognized Expert Moderator Expert
how do you call it?
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: abs |
last post by:
My element:
<span onclick="alert('test')" id="mySpan">test</span>
Let's say that I don't know what is in this span's onclick event. Is it
possible to add another action to this element's onclick event ? I've tried
something like this:
oncl = document.getElementById('mySpan').onclick
oncl = oncl + '\n;alert(\'added\')'
document.getElementById('mySpan').onclick = oncl
|
by: techfuzz |
last post by:
I scoured this group and others looking for the best way to disable a
button after the first click to prevent multiple submissions, but
never did find anything that worked like they said it would. I went
ahead and wrote my own bit of code so I'm sharing it here for
everyone. Even though it doesn't really disable the button by greying
it out, it prevents the multiple submissions which it what I was
attempting to prevent all along. ...
|
by: Nx |
last post by:
i've got it all working nicely in firefox, but whenever i test it in IE
none of the onclick events are triggered.
i'm using an xsl to transform an rss feed into a photogallery.
when i try to use setAttribute FF and safari work, but IE stops working
when i used addEventListener and attachEvent safari stops working
and when i tried .onClick,none of them worked
being fairly inexperienced (but learning fast), i figure i'm doing it
|
by: Barkster |
last post by:
I have two functions on buttons onclick, they work but if the first
fails the second still runs. How can I prevent this? Simplified Code
below. Thanks
Function Function1 () {
if (something) {
return false
}
|
by: LacrosseB0ss |
last post by:
I was wondering, can an OnClick event of a button call multiple functions?
The reason for this is I have a page that when "ok" is clicked, goes to a preview page before submitting data to the database. If "Modify" is clicked, I want to change session variables (using VB) and then go to the previous page (the easiest way I know how to do this is history.go(-1) in js).
Can OnClick call both functions? Or is there a way to do this in only...
| |
by: dnewton |
last post by:
Hi,
Can the onlclick event call multiple functions
Using ASP.NET I have created an image button that runs my form at server side and makes use of an onClick event... but...
I would also like to call a client side function when the person clicks this image button...
I am not using an <input > tag for the image button, and would rather not change it to that.
|
by: macsaregreat |
last post by:
How do you apply 2 onclick events to a check box. I googled this and
found multiple ways of doing it, but they dont work. Maybe i was not
using the correct syntax, but i cant figure it out.
these are the 2 i need to work for one check box:
"toggle(Monday1,true,Sunday1,true)"
"addUp(99, 'Monday1')"
thanks for your help
|
by: sourcie |
last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz"
I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two hotspots on the image. One being correct(a) and the other incorrect(b). When the user clicks on the correct hotspot or place on the image, it should score and retain that value until the end of the quiz. At the end of the quiz, there is a submit button...
|
by: yawnmoth |
last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html
http://www.frostjedi.com/terra/scripts/demo/this-alert2.html
Why, when you click in the black box, do the alert boxes say different
things? Shouldn't they say the same thing?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |