change button text and submit

C

Christiaan

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>
 
M

McKirahan

Christiaan said:
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>
 
J

Jeff North

On 6 Jan 2004 12:13:10 -0800, in comp.lang.javascript
| 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>

You might want to try:

<form name="frm1" action="blabla.asp" onsubmit="return
confirmButton();">
....
</form>

function confirmButton()
{
if( document.frm1.button1.value == "Save") {
document.frm1.button1.value = "Are you Sure";
return false;
} else {
document.frm1.button1.value = "Save";
return true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top