0

Hello DaniWeb members, I've just joined up and I would like to have one of my problems solved. I'm still a begginer at JavaScript coding so my request may seem a be easy for you guys to answer so here it is:

I have a JavaScript code and I want it to have a delay of 4 seconds before starting, the code is:

<SCRIPT LANGUAGE="JavaScript">
var password = ''
password=prompt('Please enter your password:','');
if (password != null) {
location.href= password + ".html";
}
</SCRIPT>

I've searched through many sites and I havn't found an answer that'll help me, so i'm hoping that you guys will. :cheesy:

Thanks - Cronos

2
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by jalarie
0

Put your script within a function and then use "setTimeout" to run the function:

TimeOut1=setTimeout("YourFunction()",4000);
0

Sorry, but could you please kindly help me place the script I have into that function? I'm very new at this, so sorry for any inconvenience.:confused:

0

The name "password" might be a reserved word, so I changed it to "pword" to avoid trouble:

<script type="text/javascript">
  function Password() {
    var password = ''
    pword=prompt('Please enter your password:','');
    if (pword == '') {
      alert('The password was null.');
    } else {
      location.href= pword + ".html";
    }
  }
  TimeOut1=setTimeout("Password()",4000);
</script>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.