Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    San Antonio, TX
    Posts
    131
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question function for an onclick, with a js alert

    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

    Code:
    <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>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    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
    Code:
    <input type="button" name="" value="Convert" onclick="Enter()">
    or
    Code:
    <input type="button" name="" value="Convert" onclick="Enter();alert('Thank You');">
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    San Antonio, TX
    Posts
    131
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thanks

    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

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    San Antonio, TX
    Posts
    131
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Perfect

    That worked Great! Thank you.

    ImperialSpider


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •