Is focus the problem?

D

David

Yes, I am new to javascript. I have a page with six boxes for 10 goals.
Because of the other tools, I am using, I cannot use a select or radio
button for each one. I have this script that works to check the valid
values for each field. It does not go back to the field with the error
when I get done. My alert tells me I have the right names at this
point. Any thoughts?

Many thanks.

<!-- Begin
function checkGrade(objValue,objName) {
var checkValue = objValue;
var checkName = objName;
var evalmeth = "0123M";
var pos = evalmeth.indexOf(checkValue);



if (pos < 0 ) {
alert(pos+":"+evalmeth+":"+checkValue+":"+checkName);
form.checkName.select();
form.checkName.focus();
return false;
}
else {
return true;
}
}
// End -->

Enter a value from 1 to 5: <input type="text" name="EvalDT1" size="20"
onchange="checkGrade(this.value,this.name)"><BR>
 
D

David

Cool. I will give it a try tomorrow. I have had a hard time finding
good, readable materials that cover all the bases.

David
 
D

David

I am not sure what I am missing. The alert displays all the right
values when there is an error, but the focus and select statements
appear to be ignored.
David

<head>
<script type="text/javascript">
// allowed grades
var evalmeth = "0123M";

<!-- Begin
function checkGrade(objValue,objName) {
var checkValue = objValue;
var pos = evalmeth.indexOf(checkValue);

if (pos < 0 ) {
alert(pos+":"+evalmeth+":"+checkValue+":"+objName.name);
objName.select();objName.focus();
}
}
// End -->


</script>
</head>

<body>
<form name="myForm" action="tryjs_submitpage.htm" >
Enter a value from 1 to 5: <input type="text" name="grade01" size="01"
onchange="checkGrade(this.value,this)"><BR>
Enter a value from 1 to 5: <input type="text" name="grade02" size="01"
onchange="checkGrade(this.value,this)"><BR>
Enter a value from 1 to 5: <input type="text" name="grade03" size="01"
onchange="checkGrade(this.value,this)"><BR>
Enter a value from 1 to 5: <input type="text" name="grade04" size="01"
onchange="checkGrade(this.value,this)"><BR>
Enter a value from 1 to 5: <input type="text" name="grade05" size="01"
onchange="checkGrade(this.value,this)"><BR>
<input type="submit" value="Submit">
</form>
</body>

</html>
 
M

Mick White

David said:
I am not sure what I am missing. The alert displays all the right
values when there is an error, but the focus and select statements
appear to be ignored.
David

<head>


<script type="text/javascript">
// allowed grades
var evalmeth = "0123M";
function checkGrade(objValue,objName) {
var pos = evalmeth.indexOf(objValue);
if (pos < 0 ) {
alert(pos+":"+evalmeth+":"+objValue+":"+objName.name);
objName.select();objName.focus();
}
}
</script>

works for me (FF)
Mick
 
D

David

Sigh. It highlights the bad field, but the cursor (focus) goes to the
next field. Am I expecting too much?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top