473,382 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 3591
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: liglin | last post by:
The following script changes the color of text with the onmousover event. How can it be modified so it changes the text when the button is clicked? I'd want to avoid layers or CSS. Thanks,...
4
by: Werner Kaiser | last post by:
Hi, I want to change the text for the file-browse button within a form: I have something like that: <FORM ENCTYPE="multipart/form-data" ACTION="<?php echo basename(__FILE__)...
5
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for...
1
by: Jurij P | last post by:
I have a problem. I would like to change a value from textbox with JavaScript before I submit the form (submit updated value). Can anyone please help me? thank you, Jure
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
1
by: Phil_Cam | last post by:
Hello All On a webpage I have a standard paypal image button for purchases. I am trying to set it up so that it only shows up or is endabled when text is entered into a textbox and a button is...
3
by: aryayudhi | last post by:
I have a html page that has javascript that works perfectly in IE, but not in Firefox. The use of this javascript to change "Tab" to "Enter" Button. When we press Tab, it is like when we press Enter...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
1
by: MZ | last post by:
Hello! Is it possible to change URL form action on submit form... I have tried such code: <script language="JavaScript" type="text/javascript"> function changeURL() {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.