Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can CONFIRM('Save Info?') be Yes/No INSTEAD of OK/Cancel

Status
Not open for further replies.

mb22

Programmer
Sep 4, 2002
258
US
Can CONFIRM('Save Info') be Yes/No INSTEAD of OK/Cancel

Is OK/Cancel the only default for using JS Confirm('Save Info?') or is there a way to change the default?
 
The only way to change it in JS is to use a popup window instead

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
how will you grab the result then? Can you get it with javascript? Any simple example?
 
In the popup, the onclick action of the 'Yes' or 'No' buttons would be to first set a javascript variable (var) in the "opener" (e.g., opener.answer = 'Y'), and then close the popup.

Good luck.

--Dave
 
do you have a sample pop-up form you can send me.... I'm kind of a newbie in JS???
 
One answer is like this:

popupParent.html
Code:
<html>
<head>
<script>
var answer = "";
function popupMessage()
{
 var popup = window.open("popup.html", "_new", "width=200,height=100");
 if(popup) popup.focus();
}

function showAnswer()
{
 alert("Answer is: " + answer);
}
</script>
</head>
<body>
<input type='button' value='Get Popup Answer' onclick='popupMessage()'/>
</body>
</html>

popup.html
Code:
<html>
<head>
<title>Your answer requested</title>
<script>
function processAnswer(answer)
{
 opener.answer = answer;
 var o = opener;
 this.opener = self;
 window.close();
 o.showAnswer();
}
</script>
</head>
<body background='Menu'>
Is this what you want?
<br />
<input type='button' value='Yes' onclick='processAnswer("Yes")' />
&nbsp;
<input type='button' value='No' onclick='processAnswer("No")' />
</body>
</html>

...but the problem with this is that (at least for me using IE6), sometimes windows that you are opening with anything other than default parameters open slooooowly.

Another solution might be to PRETEND you have a popup window. This works MUCH faster (for me, anyway). Here's an example [just one of many possible variations on the theme]:

Code:
<html>
<head>
<style>
.fakePopup
{
 background-color:'Menu';
 border-style:outset;
 position:absolute;
}
</style>
<script>
var answer = "";
function popupMessage()
{
 launchPopupButton.disabled = true;

 var rightedge=document.body.clientWidth;
 var bottomedge=document.body.clientHeight;

 popup.style.left = rightedge/2 - popup.offsetWidth/2;
 popup.style.top = bottomedge/2 - popup.offsetHeight/2;

 popup.style.visibility = "visible";
 popup.style.display = "inline";
}

function setAnswer(answerChosen)
{
 answer = answerChosen;
 popup.style.visibility = "hidden";
 popup.style.display = "none";
 alert("Answer is: " + answer);

 launchPopupButton.disabled = false;
}
</script>
</head>
<body>
<input type='button' name='launchPopupButton' value='Get Popup Answer' onclick='popupMessage()'/>
<div class='fakePopup' id='popup' style='visibility:hidden;display:none'>
<center>
<b>Is this what you want?</b>
<br />
<br />
<input type='button' value='Yes' onclick='setAnswer("Yes")' />
&nbsp;
<input type='button' value='No' onclick='setAnswer("No")' />
</center>
</div>
</body>
</html>

Good luck!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top