Hi friends,
I have a little difficulty accessing a textbox value from a function.
Here's the code:
<HTML>
<SCRIPT language = javascript>
function getdata(f){
var myArray = new Array()
for(var i = 0; i < 4; i++){//gets data
myArray[i] = f.itemboxes[i].value
}
for(var i = 0; i < 4; i++){//displays data
document.writeln( myArray[i] + "<br>")
}
var sum = 0
for(var i = 0; i < 4; i++){//adds data
sum = sum + eval(myArray[i])
}
document.writeln("The total number of items : " + sum )
}
function validatedata(f){
var pass_str = f.passbox.value
document.writeln("Your pass is : " + pass_str)
if(pass_str.length < 5 || pass_str.length > 8)
alert("Inappropriate length")
var name_str = f.namebox.value
document.writeln("Your name is : " + name_str) /*This doesnt display the name!!! */
}
</SCRIPT>
<body>
<form>
<center>
<TABLE>
item 1: <input type = text name = itemboxes value = ""> <br>
item 2: <input type = text name = itemboxes value = ""> <br>
item 3: <input type = text name = itemboxes value = ""> <br>
item 4: <input type = text name = itemboxes value = ""> <br>
password: <input type = text name = passbox value = ""> <br>
name : <input type = text name = namebox value = ""> <br></br>
<input type = button name = OK button value = "CLICK ME!" onclick = validatedata(this.form)>
</TABLE>
</center>
</form>
</body>
</HTML>
I am calling the validatedata() to get the value from the "namebox" textbox and store it in the name_str variable which is to be displayed. But it doesnt display the value of name_str.