[Javascript] javascript question. please help
BEKIM BACAJ
trojani2000 at hotmail.com
Thu Feb 27 18:58:04 CST 2003
I don't understand if you are having trouble assigning the form values to
the array, or accessing the arrays you need from the form splitting them,
but first you have to manage assingning the form values to the correspondent
arrays, than you can use them however you like.
Predefined Array length will become unusual if you change the length of the
form fields in later times.
The following will perhaps be a better way to get the field values of any
length inside the form:
**************************************************
<html>
<head>
</head>
<body>
<center>
<form name="farmform">
<input type="text" size="20" value="Cows">
<input type="text" size="4" value="77"><p>
<input type="text" size="20" value="Sheep">
<input type="text" size="4" value="120"><p>
<input type="text" size="20" value="Goats">
<input type="text" size="4" value="3"><p>
<input type="text" size="20" value="Pigs">
<input type="text" size="4" value="3"><p>
<input type="text" size="20" value="Horses">
<input type="text" size="4" value="3"><p>
<input type="text" size="20" value="Mules">
<input type="text" size="4" value="17"><p>
<input type="text" size="20" value="Chickens">
<input type="text" size="4" value="43"><p>
<input type="text" size="20" value="Ducks">
<input type="text" size="4" value="120"><p>
<input type="text" size="20" value="Raptors">
<input type="text" size="4" value="7"><p>
</form>
<Button onClick="farmcount()">GO</button>
</center>
<SCRIPT LANGUAGE=JavaScript>
var s=farmform.length;//if you put the 'GO' button inside the Form, write
s=farmform.length-1
var fn=new Array();
function farmcount(){
for(i=0; i<s; i++) {
fn[i]=' '+farmform.elements[i].value;
}
document.write(document.body.innerHTML +"<b><CENTER>"+fn+".</CENTER></b>");
}
</SCRIPT>
</body>
</html>
Any further questions...
-Post at the same forum!
Cheers!
>From: Heidi Castillo <castilloheidi at yahoo.com>
>Reply-To: javascript at LaTech.edu
>To: Javascript at LaTech.edu
>Subject: [Javascript] javascript question. please help
>Date: Thu, 27 Feb 2003 11:37:31 -0800 (PST)
>
>
>I need to know who to split a form into to arrays. can you help?
>
>
>
><html>
><head>
><script language=javascript>
>function farmcount()
>{
>
>var s=document.farmform;
>var fn= new Array(9);
>var fc= new Array(9);
>
> for(i=0; i<20; i++)
> {
> loc=i/2;
> fn(loc)=s.elements[i].value;
> }
> document.write(fn(loc));
>
>
>
>}
></script>
></head>
>
><body>
><center>
><form name="farmform">
>
><input type="text" size="20" value="Cows">
><input type="text" size="4" value="77"><p>
><input type="text" size="20" value="Sheep">
><input type="text" size="4" value="120"><p>
><input type="text" size="20" value="Goats">
><input type="text" size="4" value="3"><p>
><input type="text" size="20" value="Pigs">
><input type="text" size="4" value="3"><p>
><input type="text" size="20" value="Horses">
><input type="text" size="4" value="3"><p>
><input type="text" size="20" value="Mules">
><input type="text" size="4" value="17"><p>
><input type="text" size="20" value="Chickens">
><input type="text" size="4" value="43"><p>
><input type="text" size="20" value="Ducks">
><input type="text" size="4" value="120"><p>
><input type="text" size="20" value="Raptors">
><input type="text" size="4" value="7"><p>
>
>
><input type="button" value="GO" onClick="farmcount()">
></form>
></center>
></body>
></htnl>
>
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Tax Center - forms, calculators, tips, and more
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the Javascript
mailing list