473,473 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Button onClick + Confirm problem...

@sh
Can anyone help out here please, we have a button that when pressed will
alert the user, should they cancel no action is taken, however should they
confirm, the script will disable the button and then submit the form...

Could someone correct this lump of code for us pleaseeeeeeee ;o)
<input name="Submit" type="button" class="EmployerPostJobForm" value="
Verify Job " id="mFormSubmit" onClick="if(confirm('You are about to verify
this job, doing this will put the job live on the site and it will be
removed from this section of the site and moved to the edit jobs pages. It
will also email all candidates that are interested in this kind of job, are
you sure you wish to continue?'))return document.Verify<%= TheFormCounter
%>.mFormSubmit.disabled = true;document.Verify<%= TheFormCounter
%>.Submit();else return false;">

If we simply disable the button it works fine, however if we then try to
append onto that the form submitting action, or infact any other action, it
doesn't like it - so we're having difficulties making the result of the
Confirm action two Javascript tasks.

Many thanks

Cheers, @sh
Aug 18 '05 #1
4 2821
Lee
@sh said:

Can anyone help out here please, we have a button that when pressed will
alert the user, should they cancel no action is taken, however should they
confirm, the script will disable the button and then submit the form...

Could someone correct this lump of code for us pleaseeeeeeee ;o)
<input name="Submit" type="button" class="EmployerPostJobForm" value="
Verify Job " id="mFormSubmit" onClick="if(confirm('You are about to verify
this job, doing this will put the job live on the site and it will be
removed from this section of the site and moved to the edit jobs pages. It
will also email all candidates that are interested in this kind of job, are
you sure you wish to continue?'))return document.Verify<%= TheFormCounter
%>.mFormSubmit.disabled = true;document.Verify<%= TheFormCounter
%>.Submit();else return false;">

If we simply disable the button it works fine, however if we then try to
append onto that the form submitting action, or infact any other action, it
doesn't like it - so we're having difficulties making the result of the
Confirm action two Javascript tasks.


In the first place, that's far too much script to squeeze into an
onclick attribute. It would be easier to spot your problem and to
maintain the code if you called a function to perform these tasks.

Secondly, here's the logic of your code in a more readable form:

if(confirm(longTextString))
return document.VerifyX.mFormSubmit.disabled=true;
document.VerifyX.Submit();
else
return false;

There are a few problems with that code.
1. If the confirm() returns true, the Submit() method is not called
because the function returns.
2. I suspect that there isn't really a Submit() method defined for
this form. Did you mean "submit()". When posting code and asking
people to spot your errors, you absolutely MUST copy and paste the
exact code, not re-enter it by hand.
3. Since there is a statement between the "if" block and the "else",
you've got a syntax error.

Aug 18 '05 #2
Hi Ash,

@sh wrote:
Can anyone help out here please, we have a button that when pressed will
alert the user, should they cancel no action is taken, however should they
confirm, the script will disable the button and then submit the form...
Maybe you meant, "when they take no action, disable the button", "when
they confirm, submit the form". It's just, there's no point in
disabling the button when you're submitting the form anyway. So I'll
be assuming what I said is true.
Could someone correct this lump of code for us pleaseeeeeeee ;o)
<input name="Submit" type="button" class="EmployerPostJobForm" value="
Verify Job " id="mFormSubmit" onClick="if(confirm('You are about to verify
this job, doing this will put the job live on the site and it will be
removed from this section of the site and moved to the edit jobs pages. It
will also email all candidates that are interested in this kind of job, are
you sure you wish to continue?'))return document.Verify<%= TheFormCounter
%>.mFormSubmit.disabled = true;document.Verify<%= TheFormCounter
%>.Submit();else return false;">

[snip]

This may be the solution you're looking for:

The javascript:

function doConfirm(myForm)
{
var result = confirm("...your question...");

if(result)
{
return true;
}
else
{
myForm.elements["mFormSubmit"].disabled = true;
return false;
}
}

Your form:
<form method = "post" onsubmit = "return doConfirm(this);">
....your other form elements...
<input type = "submit" value = "Submit" id = "mFormSubmit" name =
"mFormSubmit"/>
</form>

Aug 18 '05 #3
@sh
Many thanks for that, much appreciated - we were thinking that a function is
required but Javascript and its 'exact' nature frustrates me severely and so
generally we give up.... ;o)

Perhaps I'll stick at it next time.

Thanks again.

Cheers, Ash
Aug 19 '05 #4
@sh
Thanks Lee for your reply, we did think it'd be a little too much to put
into an onClick, eitherway is it possible anyway for future reference, or
can an onClick only run a single process upon a true/false?

Cheers, Ash

Aug 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Logger | last post by:
Help, I’m trying to implement a confirm button on an asp.net page. I have it attached to a asp:button control. In the button1 click event I call the CreateConfirmBox subroutine. The Box comes...
5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
3
by: IntraRELY | last post by:
I need to attach the following 2 little scripts to an ASP.NET Button. I am having an issue with running both of the Attributes.Add. I can only get on to work at once. I have also tried to put them...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
3
by: Tarun Upadhyaya | last post by:
Hi, I am facing strange problem I read Scott mitchell's article about ASP.NET and javascript at ...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
4
by: =?Utf-8?B?QVJUTUlD?= | last post by:
i have a back button inside the code i have the following: Response.Redirect("javaScript:history.go(-1)"); I can't get the thing to work like i want it to, i want the user to click the button...
0
by: Roberto Kohler | last post by:
I created an enhanced Button Control in ASP NET 2.0 to add a delete confirmation message and to disable the button if the user does not have access. The new button control has a "ConfirmMessage"...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.