"Christiaan" <in**@asperium.com> wrote in message
news:4e**************************@posting.google.c om...
I am trying to create a small javascript to change the button text and
then submit it and do all kinds of form validations.
So I have a button with the value "Save", when the button is clicked
it should change into "Are you sure" and when you then click the
button the form must be submitted. I know this is possible using a
simple dialog box but I want to this it this way. This is what I
already have, if you have any suggestions please reply..
<head>
<script language="javascript">
<!--
function confirmButton(){
if (document.frm1.button1.value = "Save"){
document.frm1.button1.value = "Are you Sure"
}
else if (document.frm1.button1.value = "Are you sure"){
document.frm1.button1.value = "Save")
}
//-->
</script>
</head>
<body>
<form name=frm1 action="blabla.asp">
<input type=hidden>
<input type="submit" value="Save">
</form>
<body>
Clicking a button basically means "OK" so if you ask "Are you sure?" how
will they not say "OK"?
Here's a solution but with the "confirm" dialog that you don't want:
<html>
<head>
<title>r-u-sure.htm</title>
<script language="javascript" type="text/javascript">
<!--
function confirmButton() {
// { validations here }
if (!confirm("Are you sure?","")) return false;
return true;
}
//-->
</script>
</head>
<body>
<form name="frm1" action="blabla.asp" method="post" onsubmit="return
confirmButton()">
<input type="submit" value="Save">
</form>
<body>
</body>
</html>
Here's a solution based on your code but without a way to not say "OK".
<html>
<head>
<title>r_u_sure.htm</title>
<script language="javascript" type="text/javascript">
<!--
function confirmButton(){
var form = document.frm1;
if (form.button1.value == "Save") {
form.button1.value = "Are you sure?";
} else {
form.submit();
}
}
//-->
</script>
</head>
<body>
<form name="frm1" action="blabla.asp" method="post">
<input type="button" name="button1" value="Save" onclick="confirmButton()">
</form>
<body>
</body>
</html>