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:

var password = ''
password=prompt('Please enter your password:','');
if (password != null) {
location.href= password + ".html";

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:


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";