Click to See Complete Forum and Search --> : Someone care to take a look?
Nicodemas
05-20-2003, 01:50 AM
<SCRIPT LANGUAGE="JavaScript">
function checkAFSC()
{
if(this.indexOf("X")==-1)
{
alert("Your string should contain an X for the skill level");
}
}
</SCRIPT>]
Am I using this wrong? I know I'm using a good call to the object, as I've also tried the getElementByID() method.
Gollum
05-20-2003, 01:59 AM
Nic, could you include how your function is being called?
Nicodemas
05-20-2003, 02:06 AM
Sure can, here goes:
<INPUT TYPE="text" NAME="requiredstrAFSC" SIZE="20" onBlur="checkAFSC()">
The FORM tag itself looks like this:
<FORM ACTION="tally.asp" METHOD="post" onSubmit="return checkrequired(this)">
Gollum
05-20-2003, 02:32 AM
OK, I see the problem...
I'm assuming you're thinking 'this' is the INPUT element that you can refer to during the onblur event. Trouble is the onblur event handler is not checkAFSC() as you might think, but a just-in-time created function containing the code you specified in the onblur attribute.
It would be similar to this...
<INPUT TYPE="text" NAME="requiredstrAFSC" SIZE="20">
function onBlurHandler() { checkAFSC(); }
document.forms[0].requiredstrAFSC.onblur = onBlurHandler;
now you can see that the this keyword makes sense in the handler function, but your function is called outside the scope of the input object so 'this' doesn't make sense.
you could try this...
<SCRIPT LANGUAGE="JavaScript">
function checkAFSC(oThis)
{
var str = oThis.value;
if(str.indexOf("X")==-1)
{
alert("Your string should contain an X for the skill level");
}
}
</SCRIPT>
<INPUT TYPE="text" NAME="requiredstrAFSC" SIZE="20" onBlur="checkAFSC(this);">
Lucky Punch
05-20-2003, 02:34 AM
This code-snippet will probably work. Hope it helps.
<SCRIPT LANGUAGE="JavaScript">
function checkAFSC()
{
if(document.forms.myFORM.requiredstrAFSC.value.indexOf("X")==-1)
{
alert("Your string should contain an X for the skill level");
}
}
</SCRIPT>]
<FORM NAME="myFORM" ACTION="" METHOD="post" onSubmit="return checkrequired(this)">
<INPUT TYPE="text" NAME="requiredstrAFSC" SIZE="20" onBlur="checkAFSC()">
</FORM>
Nicodemas
05-20-2003, 03:07 AM
Thanks, my preciousss.