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

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

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

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:

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.