English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

For example, I want to change this:

prefer = document . forms[0] . firstname . value

To:

prefer = document . forms[0] . ***variable here*** . value

My goal is to write a function which handles any given field, not just a specific one. Maybe I'm not approaching the problem correctly in the first place; I'm pretty new to JS. Please advise.

Thanks!

2006-09-04 09:22:41 · 5 answers · asked by tonybgoode 2 in Computers & Internet Programming & Design

5 answers

just put the variable in [ ], test sample below











BlueSagi
zkvneml@hotmail.com

2006-09-05 17:35:19 · answer #1 · answered by Zhao_Kevin 1 · 0 0

that's not actually DOM you know...

if you were using DOM, you'd be using th getElementById() function and not the deprecated non standard one.

Anyway.

if you give your form the ID form01

youd catch it like this
prefer = document.getElementById("form01");
then you can acces what's underneath with the array
form01.childNodes[x].value where x is a number

Although this may not be the best aproach because you'll get ALL the child nodes, if you only want the input items you need to use it like this (after you used getElement...).

inputArray = prefer.getElementsByTagName("input");

that'll generate an array with the input fields, text, buttons, passwords..etc except select, radio and option.

you can acces the value with inputArray[x].value
this will not work as you might expect in some interpreters, so use it wisely, for example only use that command in a for construction, and to anything else separately.

2006-09-04 09:32:42 · answer #2 · answered by Dragosh 3 · 0 0

Just try put in front:
document.forms[0].variable = document.forms[0].firstname
see that helps or not

JavaScript has a simple, limited, built-in Reflection using foreach loop hope that helps with any use; member objects can be programmed to a loop because instead of resolution . they can be accessed like maps just like in Python.

2006-09-04 09:33:09 · answer #3 · answered by Andy T 7 · 0 0

Take a look of the loop for javascript!
you will found it !

2006-09-04 18:43:21 · answer #4 · answered by Jimmy 1 · 0 0

Gave me: Text Heading | August with borders. Ron

2016-03-26 22:03:03 · answer #5 · answered by ? 4 · 0 0

fedest.com, questions and answers