I need to know how to pass variables because I want to use the same
function to varify multiple data imput boxes.
Please tell me what's wrong with this code.
<head>
<script language="JavaS cript">
function myFunction(this ){
entry=document. Forms[0].this.value;
if (document.Forms[0].this.value=="" ){
document.Forms[0].this.focus();
}
else {
// Do something with "entry" here
}
if (this = "inputBox2" ) {
document.Forms[0].total.value = document.Forms[0].inputBox1.valu e +
document.Forms[0].inputBox2.valu e;
}
}
</script>
</head>
<body>
<form>
<input type="text" name="inputBox1 " onBlur="myFunct ion(this)">
<input type="text" name="inputBox2 " onBlur="myFunct ion(this)">
<input type="text" name="total">
</form>
</body> 2 27298
Ed wrote: I need to know how to pass variables because I want to use the same function to varify multiple data imput boxes.
Please tell me what's wrong with this code.
<head> <script language="JavaS cript"> function myFunction(this ){
"this" is a keyword representing the current object, it shouldn't and can't
be used as a parameter name.
Try
function myFunction(refe renceToAnInput) {
entry=document. Forms[0].this.value;
You've got a reference to the form element itself, it's unnecessary to
reference the input this way. Simply use:
var entry = referenceToAnIn put.value;
if (document.Forms[0].this.value=="" ){
You store the input's value in a variable then you don't use it. If you're
retrieving "entry", then make use of it:
if (entry == "") {
document.Forms[0].this.focus();
referenceToAnIn put.focus();
} else { // Do something with "entry" here } if (this = "inputBox2" ) {
if (referenceToAnI nput.name == "inputBox2" ) {
document.Forms[0].total.value = document.Forms[0].inputBox1.valu e +document.Forms[0].inputBox2.valu e;
var referenceToTheF orm = referenceToAnIn put.form;
referenceToTheF orm.total.value =
parseFloat(refe renceToTheForm. inputBox1.value ) + parseFloat(entr y);
You need to parseFloat() because the values in input boxes are strings, if
you simply added them together with "+", it would concatenate them, not add
their numeric values (see <url: http://jibbering.com/faq/#FAQ4_21 />)
Since you retrieve "entry" at the beginning of the function, you might as
well use it here rather then retrieving it again.
} } </script> </head> <body> <form> <input type="text" name="inputBox1 " onBlur="myFunct ion(this)"> <input type="text" name="inputBox2 " onBlur="myFunct ion(this)"> <input type="text" name="total"> </form> </body>
Note that by using the onblur event, and putting focus back on the input
when the input is invalid, you've trapped the user in that input until they
enter something, and created a situation that could lead to an endless loop
where they blur the input, you put the focus back on it, some other sequence
of events blurs it again and so on.
--
| Grant Wagner <gw*****@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
I've played with your code for hours and keep getting "Expecting an Object"
Grant Wagner wrote: Ed wrote:
I need to know how to pass variables because I want to use the same function to varify multiple data imput boxes.
Please tell me what's wrong with this code.
<head> <script language="JavaS cript"> function myFunction(this ){
"this" is a keyword representing the current object, it shouldn't and can't be used as a parameter name.
Try
function myFunction(refe renceToAnInput) {
entry=document. Forms[0].this.value;
You've got a reference to the form element itself, it's unnecessary to reference the input this way. Simply use:
var entry = referenceToAnIn put.value;
if (document.Forms[0].this.value=="" ){
You store the input's value in a variable then you don't use it. If you're retrieving "entry", then make use of it:
if (entry == "") {
document.Forms[0].this.focus();
referenceToAnIn put.focus();
} else { // Do something with "entry" here } if (this = "inputBox2" ) {
if (referenceToAnI nput.name == "inputBox2" ) {
document.Forms[0].total.value = document.Forms[0].inputBox1.valu e +document.Forms[0].inputBox2.valu e;
var referenceToTheF orm = referenceToAnIn put.form; referenceToTheF orm.total.value = parseFloat(refe renceToTheForm. inputBox1.value ) + parseFloat(entr y);
You need to parseFloat() because the values in input boxes are strings, if you simply added them together with "+", it would concatenate them, not add their numeric values (see <url: http://jibbering.com/faq/#FAQ4_21 />)
Since you retrieve "entry" at the beginning of the function, you might as well use it here rather then retrieving it again.
} } </script> </head> <body> <form> <input type="text" name="inputBox1 " onBlur="myFunct ion(this)"> <input type="text" name="inputBox2 " onBlur="myFunct ion(this)"> <input type="text" name="total"> </form> </body>
Note that by using the onblur event, and putting focus back on the input when the input is invalid, you've trapped the user in that input until they enter something, and created a situation that could lead to an endless loop where they blur the input, you put the focus back on it, some other sequence of events blurs it again and so on.
-- | Grant Wagner <gw*****@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at: * http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at: * http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at: * http://www.mozilla.org/docs/dom/domref/ * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla * http://www.mozilla.org/docs/web-deve...upgrade_2.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Amr Mostafa |
last post by:
Hello :)
I'm trying to write a script that deals with a web service.
I'm using NuSoap class.
my question is : Can I pass some variables By Reference to the web
service and get the result back in my variables ??
note1: I'm not the one who wrote the web service.. so I can't modify
|
by: Jason Us |
last post by:
Does anyone have experience with passing variables from an ASP page to
a JSP page.
The way it currently works in passing the SSN in the URL. This cannot
be good.
I thought that storing a unique session ID in a cookie and referencing
the SSN from the Session ID would be the correct way to do this. But
since we have two separate servers, IIS and Websphere, how do we
coordinate the session ID?
|
by: domeceo |
last post by:
can anyone tell me why I cannot pass values in a setTimeout function
whenever I use this function it says "menu is undefined" after th
alert.
function imgOff(menu, num) {
if (document.images) {
document.images.src = eval("mt" +menu+ ".src")
}
alert("imgOff_hidemenu");
hideMenu=setTimeout('Hide(menu,num)',500);
|
by: Jack |
last post by:
Hi,
I need to pass multple variables in a link in order to go to a asp page with
the
two varables.
The following are the values of the variables using response.write:
<%'Response.Write Mypage & "<br>"%>
Exp
<%'Response.Write GrantID & "<br>"%>
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of code...
TCHAR myArray;
DoStuff(myArray);
| |
by: Gregory Piñero |
last post by:
Hey guys, would someone mind giving me a quick rundown of how
references work in Python when passing arguments into functions? The
code below should highlight my specific confusion:
<code>
bool1=True
lst1=
def func1(arg1): arg1.append(4)
|
by: Scott Zabolotzky |
last post by:
I'm trying to pass a custom object back and forth between forms.
This custom object is pulled into the app using an external reference
to an assembly DLL that was given to me by a co-worker. A query-string
flag is used to indicate to the page whether it should instantiate
a new instance of the object or access an existing instance from
the calling page.
On the both pages I have a property of the page which is an
instance of this custom...
|
by: Lee |
last post by:
Hi All
How can I pass options from one webpage into another webpage. When the user
clicks on the hyperlink I want them to be go to the next page but I need to
pass in a number that the next page needs to reference.
Thanks
Lee
|
by: Andrew Bullock |
last post by:
Hi,
I have two classes, A and B,
B takes an A as an argument in its constructor:
A a1 = new A();
B b = new B(a1);
|
by: BezerkRogue |
last post by:
This is the most fundamental action I am sure, but I can't seem to make it happen.
I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have some scripts that run at the server for the form so I can't disable that statement. I followed Microsoft's instructions(I know..not the best thing to do) but still can't get the variables to pass.
I created a class and set up an @reference...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |