Prompt validation

hi,
i have a javascript funtion


function verifyOverwrite(){
var name = prompt('please enter name'); 
	if(name == 'homer'){
		return true;
	}else{
		return false;
	}

}

and a link

<a href="" onclick="verifyOverwrite()">OVERWRITE</a>

when i click the link, a prompt will popup, if i enter the correct name
it will continue to go to the link, if i enter wrong name, then it will not.

anyone please help

tia

If you’re relying on the return value you must capture it in the onclick handler, and the link must have an href specified:

function verifyOverwrite()
{
 return prompt( 'Please enter name' ).toLowerCase() == 'homer';
}

<a href="[B]theurlHere[/B]" onclick="[B]return[/B] verifyOverwrite()">OVERWRITE</a>

Of course that allows the target location to be seen in the status bar, so you could prevent that an make the function more reusable.
It’s totally insecure but obviously this is just an academic exercise:

<html>
<head><title>LINK</title></head>
<script type="text/javascript">

function verifyOverwrite( url, pw )
{
  if( prompt( 'Please enter name' ).toLowerCase() == pw.toLowerCase() )
   location.href = url;
   
  return false;
}

</script>
<body>
<a href="#" onclick="return verifyOverwrite( 'http://google.com', 'homer' )">OVERWRITE</a>
</body>
</html>

wow, you help me a lot…!
thanks buddy!
that solves my problem…:smiley: