Forum Moderators: open
function language(field)
{
var x = document.forms.getElementByName(field).value;
return x;
}
there is a input hidden field into my form named as follows...
<input type="hidden" name="vcontact" id="vcontact" value="0">
I call the functions this way when validating the form...
if(language("vcontact") == 0)
nameInfo.text("enter a name with more than 3 letters!")
else
nameInfo.text("digite um nome com mais de 3 letras!");
0 = US (english messages)
1 = BR (portuguese messages)
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; InfoPath.2; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
Timestamp: Mon, 11 May 2009 21:57:17 UTC
Message: Object doesn't support this property or method
PLEASE HELP me with this ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">
<!-- put doctype all on one line -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
function checkLen(form) {
if (document.getElementById) {
var x = (document.getElementById('lang-en').checked==true)?0:1;
var d = document.getElementById('nameInfo');
var e = document.getElementById('warn');
var val = document.getElementById('username').value;
if (val.length < 4) {
e.style.display="block";
if (x == 0) { d.value='enter a name with more than 3 letters!'; }
else { d.value='digite um nome com mais de 3 letras!'; }
//alert(d.value);
}
else { form.submit(); }
}
return false;
}
function clearField() {
document.getElementById('nameInfo').value='';
var e = document.getElementById('warn');
e.style.display="none";
}
</script>
</head>
<body>
<form method="post" action="" onSubmit="return checkLen(this);">
<p><input type="radio" name="lang" id="lang-en" value="0" onClick="clearField();" checked>
<label for="lang-en">US</label>
<input type="radio" name="lang" id="lang-br" onClick="clearField();" value="1">
<label for="lang-en">BR</label></p>
<p><input type="text" name="username" id="username" value=""></p>
<p id="warn" style="display:none">
<input type="text" name="nameInfo" id="nameInfo" size="55" value=""
onFocus="blur()" style="border:none;">
</p>
<p><input type="submit" value="submit"></p>
</form>
</body>
</html>
<input type="hidden" name="vcontact" id="vcontact" value="0">
inside my script.js file
function langcheck(field)
{
var x = document.forms.getElementByName(field).value;
return x;
}
I will use the same function for different forms, so I pass to the function the NAME of the control (vcontact) like
var mycomp = langckeck('vcontact');
Therefore inside my function, (field) is supposed to carry "vcontact" control, and x must return 0, what will end with mycomp = 0... But it is failing!
If I have to do the reference inside my function again to the document.forms.getElementByName with the actual name of the control there is no point of using the function with the field agrument...
Alternatively, you could use getElementsByName, which returns a collection of elements with that name. But you'd then need to access the particular element within that collection that you are trying to access.
if(langcheck('vcontac') == 0) works
if(langcheck("vcontac") == 0) DOES NOT!
function langcheck(field) { var x = document.getElementById(field); return (x != null? x.value: null); }
returns undefined value...
the original function was just fine, except by the little detail... ;) Never again!
Thanks very much for all of your time ad effort to make my life easier...