Weid behaviour calling value of a selfmade JS class
Hi,
I experienced some weird behaviour when alerting the value of a selfmade JS class.
I made the class myTestobj with one property called 'value'. The object 'mytest' is of that type. If I alert 'mytest.value' before the formtag it says 'Normal behaviour' as expected. But when I alert it inside the form it says 'Not so normal behaviour!'.
As you can see I have an element with the name 'mytest' in the form.
Why does it alert the value of this element when I call it inside the form and not the value of my object?
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
<title>Weird behaviour</title>
<script type="text/javascript">
function myTestobj(){
this.value = 'Normal behaviour';
}
var mytest = new myTestobj();
</script>
</head>
<body>
<input type="button" onclick="alert(mytest.value);" value="Before the form">
<form>
<input type="button" onclick="alert(mytest.value);" value="In the form">
<table>
<tr>
<td><input type="text" name="mytest" value="Not so normal behaviour!" /></td>
</tr>
</table>
</form>
</body>
</html>