Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select() with OnChange="check(this)"

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
0
0
NL
Hi there,

I've got this code:

Code:
<script language="JavaScript">
<!--
function CheckBanknr(val) {
if ("".replace) 
	{
	waarde = val.value;
	var rekNr = String(waarde).toUpperCase().replace(/[\s\t-\.]/g,""); // Delete white space, hyphens en periods
	if (rekNr.match(/[^P^0-9]/g)) 
		{
		// If anything left is not a digit or a P then it's not an rekeningnr
		alert ('The rekeningnummer is not valid!!!');
		return false;
		}
	}
}
//-->
</script>

<body>
<form method=post action="" name="betalen">
<input type="text" name="rek_nr1" onChange="return(CheckBanknr(this))" size=9 maxlength=9>
<input type="text" name="rek_nr2"  onChange="return(CheckBanknr(this))"size=9 maxlength=9>
<input type="text" name="rek_nr3"  onChange="return(CheckBanknr(this))"size=9 maxlength=9>
</form>
</body>

and I'd like to add a focus() or select() to the formfield that was just validate if the vlaue was invalid.

I'm just starting to work with CheckBanknr(this), my first script where I use "(this)". Usually I create of someting like: document.forms['betalen']elements['reknr1'].focus() but I'd like to focus with that "this"

Just changing
Code:
if (rekNr.match(/[^P^0-9]/g)) 
		{
		// If anything left is not a digit or a P then it's not an rekeningnr
		alert ('The rekeningnummer is not valid!!!');
		return false;
		}
to
Code:
if (rekNr.match(/[^P^0-9]/g)) 
		{
		// If anything left is not a digit or a P then it's not an rekeningnr
		alert ('The rekeningnummer is not valid!!!');
		this.focus();
		return false;
		}
did not work.... What is the right way to do this??

T.I.A.

Don't eat yellow snow!
 
Change this
>[tt]this.focus();[/tt]
to this
[tt][red]val[/red].focus();[/tt]
 
Thanks.... that was easy! I'm getting the hang of "this" now...

Don't eat yellow snow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top