hi all,
I'm writing a function that, say, loop through input fields in a form
and set default values to it. Some fields are dependent thus I have
some onChange scripts to kick off corresponding actions to those
fields.
<form name="test">
<input type="text" name="text1">
<input type="text" name="text2" onChange="text1.value+=this.value;">
<input type="text" name="text3" onChange="doSomething();">
</form>
<script language="JavaScript">
function setDefault(form) {
var fields = form.elements;
for (var i=0; i<fields.length; i++) {
// for each field, somehow get a default value and set it.
}
}
</script>
......
[OnChange] catches only browser actions as far as I understand. That
means when I set a value to "text2" via the method, the corresponding
action isn't triggered.
I can get the actions of a corresponding field by:
var actn = field.onchange;
alert( actn );
which shows:
anonymous() {
doSomething();
}
Despite being able to get all those actions and store them in a
variable, I don't know how to execute them. Do anyone has a clue?
Thanks very much
George 8 1489
Hello
"xxgeorge" <xx******@yahoo.com> wrote in message
news:e9**************************@posting.google.c om... hi all,
I'm writing a function that, say, loop through input fields in a form and set default values to it. Some fields are dependent thus I have some onChange scripts to kick off corresponding actions to those fields.
<form name="test"> <input type="text" name="text1"> <input type="text" name="text2" onChange="text1.value+=this.value;"> <input type="text" name="text3" onChange="doSomething();"> </form>
<script language="JavaScript"> function setDefault(form) { var fields = form.elements; for (var i=0; i<fields.length; i++) { // for each field, somehow get a default value and set it. } } </script> .....
[OnChange] catches only browser actions as far as I understand. That means when I set a value to "text2" via the method, the corresponding action isn't triggered.
I can get the actions of a corresponding field by: var actn = field.onchange; alert( actn );
which shows: anonymous() { doSomething(); }
Despite being able to get all those actions and store them in a variable, I don't know how to execute them. Do anyone has a clue?
Hmm...
You wanted to execute a given action?
Why not call it directly w/o storing it in a variable as:
field.onChange(field); // <-- sending it the 'this' or itself
or
field.onChange();
HTH,
Elias
On Wed, 11 Aug 2004 11:05:04 +0300, lallous <la*****@lgwm.org> wrote:
[snip] Why not call it directly w/o storing it in a variable as: field.onChange(field); // <-- sending it the 'this' or itself or field.onChange();
Remember that the properties are case-sensitive, unlike HTML. It should be:
field.onchange();
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
"lallous" <la*****@lgwm.org> wrote in message news:<2n************@uni-berlin.de>... Hello
Hmm...
You wanted to execute a given action?
Why not call it directly w/o storing it in a variable as: field.onChange(field); // <-- sending it the 'this' or itself or field.onChange();
HTH, Elias
oh thx, that do the trick. how I can miss this :)
Anyway, just for interest, still want to know if there's any way to
invoke a method obj. I mean something like "mthd.call()".
One more question. is there any way to list out all fields and
methods of an object? say I have the "mthd" object, how can I know
its attributes?
many thx
xxgeorge
"xxgeorge" <xx******@yahoo.com> wrote in message
news:e9*************************@posting.google.co m... "lallous" <la*****@lgwm.org> wrote in message
news:<2n************@uni-berlin.de>... Hello
Hmm...
You wanted to execute a given action?
Why not call it directly w/o storing it in a variable as: field.onChange(field); // <-- sending it the 'this' or itself or field.onChange();
HTH, Elias
oh thx, that do the trick. how I can miss this :) Anyway, just for interest, still want to know if there's any way to invoke a method obj. I mean something like "mthd.call()".
One more question. is there any way to list out all fields and methods of an object? say I have the "mthd" object, how can I know its attributes?
<script language="JavaScript">
<!--
for (x in document)
document.write(x + "<br>");
//-->
</script>
--
Elias
> One more question. is there any way to list out all fields and methods of an object? say I have the "mthd" object, how can I know its attributes?
Firefox has an object viewer. http://www.mozilla.org/products/firefox/
You can loop through all the first level members of an object with:
for (i in obj)
{
}
You would have to put in check for nested objects etc.
Robert xx******@yahoo.com (xxgeorge) wrote: "lallous" <la*****@lgwm.org> wrote in message news:<2n************@uni-berlin.de>... Hello Anyway, just for interest, still want to know if there's any way to invoke a method obj. I mean something like "mthd.call()".
function f() { alert('hello') }
mthd = f;
mthd();
Regards,
Steve
hi all,
thx for all your response. I now have another question. I'm trying
to write a similar piece of script that automatically turns all text
field data into uppercase. Here's the script I put at the bottom of
my page:
<script language="JavaScript">
var form = window.document.myForm;
var fields = form.elements;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
if (field.type.toUppercase().indexOf("TEXT")>=0) {
field.onblur = toUpperCase;
}
}
function toUpperCase() {
var field = window.event.srcElement;
field.value = field.value.toUpperCase();
}
</script>
It works fine but the question is, what if the field originally has a
onBlur function? how can I tell it to do both it's own function and
mine?
Thanks for your help
george
On 19 Aug 2004 21:30:57 -0700, xxgeorge <xx******@yahoo.com> wrote: thx for all your response. I now have another question. I'm trying to write a similar piece of script that automatically turns all text field data into uppercase. Here's the script I put at the bottom of my page:
<script language="JavaScript">
Valid HTML requires the use of the type attribute. The language attribute
has been deprecated and should not be used.
<script type="text/javascript">
var form = window.document.myForm;
No need to use window.
var fields = form.elements; for (var i=0; i<fields.length; i++) { var field = fields[i]; if (field.type.toUppercase().indexOf("TEXT")>=0) {
The type property returns a lowercase string. There is no reason to
convert it to uppercase. Also, if the field is an INPUT of type text, only
'text' will be returned.
if(field.type == 'text') {
field.onblur = toUpperCase; } } function toUpperCase() { var field = window.event.srcElement; field.value = field.value.toUpperCase();
You should be able to change that to
this.value = this.value.toUpperCase();
as the this operator will reference the object that is handling the event
(the text field).
} </script>
It works fine but the question is, what if the field originally has a onBlur function? how can I tell it to do both it's own function and mine?
It depends on your target environment. If this is to be used on an
Intranet, the browsers available will offer different approaches. For
example, IE allows
obj.attachEvent(type, listener) [1]
whilst DOM-compliant browsers offer
obj.addEventListener(type, listener, capture) [2]
However, if this is for the Web, you'll need a much more intricate method.
So, restricted environment, or the Web?
Mike
[1] The type parameter is the event name with the 'on' prefix.
[2] The type parameter is the event name *without* the 'on' prefix.
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: Andrew V. Romero |
last post by:
I have been working on a function which makes it easier for me to pull
variables from the URL. So far I have:
<script language="JavaScript">
var variablesInUrl;
var vArray = new Array();
...
|
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) {...
|
by: Thomas Matthews |
last post by:
Hi,
I'm getting linking errors when I declare a variable in the
global scope, but not inside a function. The declarations
are the same (only the names have been changed...).
class Book
{...
|
by: Andrew Poulos |
last post by:
I tested the JSON parse/to code from json.org and it works but I don't
understand how. Could someone explain how something in this format works:
(function() {...})();
Andrew Poulos
|
by: Ray |
last post by:
Hello,
I think I've had JavaScript variable scope figured out, can you please
see if I've got it correctly?
* Variables can be local or global
* When a variable is declared outside any...
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: ...
|
by: Larax |
last post by:
Best explanation of my question will be an example, look below at this
simple function:
function SetEventHandler(element)
{
// some operations on element
element.onclick =
function(event)
{
|
by: alex |
last post by:
I am so confused with these three concept,who can explained it?thanks
so much?
e.g.
var f= new Function("x", "y", "return x * y");
function f(x,y){
return x*y
}
var f=function(x,y){
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |