• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

javascript question

gigapet

Lifer
I need a piece of code that will send an alert window to the screen ask a question and it needs to have two buttons yes and no. If the user clicked yes it will do one thing if they clicked no it will do another.

Thanks in advance for your help.

 
I don't think you can do it with alert. alert doesn't allow decisions. It simply displays the message and says "OK" as the only button. You're going to want to use confirm instead.

function confirmSomething()
{
if (confirm("Are you sure you want to do Something?"))
{
'something
}
else
{
' not something
}
}

You'd then call this via an event (click, pageload, etc.)

Edit -
You can see an small example running http://www.2report.com/jsexample.html
 
JS doesn't really have a Yes/No dialog, but it does have an OK/Cancel one. Depending on what the user chooses, it'll perform different actions. Look up the JavaScript "Confirm" function in Google. If you're looking to alienate everyone NOT using IE, you can use VBScript code posted here. There's another option listed on this messageboard which may also help.
 
^ usually use that on a Submit button but dont label it as submit....
have type=button on the input tag...when they click that the 'something gets replaced by form.submit() 😀

code:
<script language="JavaScript">
function check(){
if(confirm('Are you sure?')){
alert('OK');
} else {
alert('try again');
}
}
</script>
<input type=button onClick="check()">
 
Back
Top