Forum Moderators: open

Message Too Old, No Replies

Display confirmation message

         

billybaroo

7:21 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



Hi,
I'm using the script below which I only want to appear once. Depending on what action the user has taken it will then either continue with the form and it's validation or return to the home page.

I do realise that this is not the most user friendly way, but my friend does insist having this.

function confirmation(){
var answer = confirm("Do you wish to continue?")
if (answer){
window.location = "http://www.mydomain.com/form.html";
}
else{
window.location = "http://www.mydomain.com";
}
}

Any help would be appreciated.
Billy

fcxsebs

7:49 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



Where are you calling this from?

billybaroo

9:01 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



Hi fcxsebs,
I will start again as my original post was not too clear.

I'm using the script below which displays a confirmation message when this form page is loaded. Using this script as is will loop if they agree, I’m not an experienced programmer so I would like some help to add some function to it so it will not loop but will display the confirmation message once when visited.

If the user wishes to continue they will be shown the form page, if they disagree they will be sent to the home page.

I do realise that this is not the most user friendly way, but my friend does insist having this.

JavaScript
function confirmation(){
var answer = confirm("Do you wish to continue?")
if (answer){
window.location = "http://www.mydomain.com/form.html";
}
else{
window.location = "http://www.mydomain.com";
}
}

html
<body id="test" onLoad="confirmation()">
<form action="" method="post" name="test" id="test">
<fieldset>
<legend>About You</legend>
<p>
<label>Firstname</label><br />
<input name="fname" type="text" id="fname">
</p>
<p><label>Surname</label><br />
<input name="sname" type="text" id="sname">
</p>
<p>
<label>Email</label><br />
<input name="email" type="text" id="email">
</p></fieldset>
<input type="submit" name="Submit" value="Submit">
</form>
</body>

Thanks in advance for any help on this
Billy

garann

9:06 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



If all you want is to stay on the same page when the user says Yes, you just need this:

function confirmation(){
if (!confirm("Do you wish to continue?")) window.location = "http://www.mydomain.com";
}

That won't reload your page and cause the looping.

billybaroo

9:15 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



Hi Garann,
Thats great, it works a treat and so simple.

Thanks for the quick respone.
Billy