Got a form field that's being checked by a function if value is numeric or not. After the returning the check, I need another function that is meant to pass an attribute value to the field.
Example:
- FunctionA checks if value is numeric or not
- FunctionB get a specific digit from FunctionA which is set as the attribute of the form field
- If form field value is numeric, set the maxlength to 20
- Else if it's not numeric, set the maxlength to 10
HTML:
<form method="post" action="">
<input type="text" name="txt" onblur="numChk(this.value);" maxlength="getMax();" />
<p id="fmsg"></p>
<input type="submit" name="sub" />
</form>
Javascript:
<script type="text/javascript">
function numChk (num){
//var num = num;
if(!isNaN(num)){
document.getElementById("fmsg").innerHTML = '<strong>' + num + ' is a number </strong>';
getMax(maxVal) = 14;
} else{
document.getElementById("fmsg").innerHTML = '<em>' + num + ' is not a number </em>';
getMax(maxVal) = 11;
}
}
function getMax(maxVal){
return maxVal;
}
</script>
Hope to get some help with this.