469,579 Members | 1,214 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

change button text and submit

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>
Jul 20 '05 #1
4 3436
"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>
Jul 20 '05 #2
In article <QXFKb.760357$Tr4.2159619@attbi_s03>, "McKirahan"
<Ne**@McKirahan.com> writes:
Here's a solution based on your code but without a way to not say "OK".
<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();
}
}


The language attribute is not needed, nor are the HTML Entities for comments.

But, why does that not allow for the user to confirm? It requires two clicks of
the button, if you want to cancel it, simply don't click it again.
--
Randy
Jul 20 '05 #3
In article <4e**************************@posting.google.com >, in**@asperium.com
(Christiaan) writes:
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">
language is deprecated, use type="text/javascript" instead
<!--
The HTML Entity for a comment is no longer needed.

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")
}


Using = sets a property, == compares them, === compares type as well as value.

inside your if statements, you need == instead of =.
So, it will always result in the first one executing.
There is also no need for the second if statement.
The only way it will make it to the else is if the value has been changed, so
theres no point in testing it again.

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

--
Randy
Jul 20 '05 #4
On 6 Jan 2004 12:13:10 -0800, in comp.lang.javascript
in**@asperium.com (Christiaan) wrote:
| 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;
}
}
---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by liglin | last post: by
4 posts views Thread by Werner Kaiser | last post: by
1 post views Thread by Phil_Cam | last post: by
1 post views Thread by MZ | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.