...

View Full Version : function for an onclick, with a js alert



ImperialSpider
01-19-2006, 08:10 PM
I am trying to call a function with onclick, and have an javascript alert popup immediately following the execution of the function. below is my code...can someone tell me what I need to do to have this function execute, and then immediately have the alert pop up once the function has executed?

Any help would be greatly appreciated...

Thanks,
Imperial Spider



<html>
<head>
<title>PASSWORD CONVERTER</title>
<script language="JavaScript" type="text/javascript">
<!--

var Obj,PassWord,Star,Nu;

function Enter(){
Obj=document.getElementById('passw');
PassWord=Obj.value;
if (PassWord.length<8){
alert('Minimum of Eight Charactors');
return;
}
document.getElementById('mypassw').value=PassWord;
Star='*';
Nu=1;
Change();
}

function Change(){
Obj.value=Star+PassWord.substring(Nu,PassWord.length);
Star+='*';
Nu++;
if (Nu<PassWord.length){ setTimeout('Change()',20) }
else {
Obj.value=Star;
Obj.setAttribute('disabled','disabled');
Obj.style.backgroundColor='silver';
}
}

//-->
</script>
</head>

<body>
Input your password below, and click on the "Convert" button<p>
<input id="passw" size="10"><input type="hidden" id="mypassw" name="mypassw" size="10">
<input type="button" name="" value="Convert" onclick=Enter() "alert('Thank You');">
</html>

_Aerospace_Eng_
01-19-2006, 08:17 PM
function Enter(){
Obj=document.getElementById('passw');
PassWord=Obj.value;
if (PassWord.length<8){
alert('Minimum of Eight Charactors');
return;
}
document.getElementById('mypassw').value=PassWord;
Star='*';
Nu=1;
Change();
alert('Thank You')
}
Then the input box would use this for the onclick

<input type="button" name="" value="Convert" onclick="Enter()">
or

<input type="button" name="" value="Convert" onclick="Enter();alert('Thank You');">

ImperialSpider
01-19-2006, 10:34 PM
That does add both the function, and the alert, but the alert is coming up before th function has time to complete...is there a way to have the alert wait until the function is complete? maybe with an if, then statement, but not sure how to do it. any ideas???

Thanks again for your help _Aerospace_Eng_

Imperial Spider

_Aerospace_Eng_
01-19-2006, 10:43 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PASSWORD CONVERTER</title>
<script type="text/javascript">
<!--
var Obj,PassWord,Star,Nu;

function Enter(){
Obj=document.getElementById('passw');
PassWord=Obj.value;
if (PassWord.length<8){
alert('Minimum of Eight Charactors');
return false;
}
document.getElementById('mypassw').value=PassWord;
Star='*';
Nu=1;
Change();
return false;
}

function Change(){
Obj.value=Star+PassWord.substring(Nu,PassWord.length);
Star+='*';
Nu++;
if (Nu<PassWord.length){
setTimeout('Change()',20)
}
else {
Obj.value=Star;
Obj.setAttribute('disabled','disabled');
Obj.style.backgroundColor='silver';
alert('Thank You');
}
}

//-->
</script>
</head>
<body>
Input your password below, and click on the "Convert" button
<form action="#" method="post" onsubmit="return Enter()">
<p>
<input id="passw" size="10"><input type="hidden" id="mypassw" name="mypassw" size="10">
<input type="submit" name="" value="Convert">
</p>
</form>
</body>
</html>
I used a submit button instead because it allows the user to just hit enter or they can hit convert. Either or will work.

ImperialSpider
01-21-2006, 06:47 AM
That worked Great! Thank you.

ImperialSpider



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum