Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disable button and validate data in javascript

Posted on 2013-01-06
4
Medium Priority
?
488 Views
Last Modified: 2013-01-07
I have this function that works great :
function disableBtn(btnID, newText) {
    var btn = document.getElementById(btnID);
    //setTimeout("setImage('"+btnID+"')", 10);
    btn.style.background = "background-image: url('../images/indicator.gif') no-repeat";
    btn.disabled = true;
    btn.value = newText;
}
I associate to a buton tihs way:
 <asp:Button ID="Bt_save" runat="server" onclick="Bt_save_Click" onclientclick="disableBtn(this.id, 'Submitting...')" UseSubmitBehavior="false"  Text="Save Changes" />

So far everything is good, the only issue is that I need to validate data from my form in JAvascript.
So if I add something like :
 <asp:Button ID="Bt_save" runat="server" onclick="Bt_save_Click" onclientclick="return confirm('Do you want to save?');disableBtn(this.id, 'Submitting...')" UseSubmitBehavior="false"  Text="Save Changes" />, it does not work anymore.

Thanks
0
Comment
Question by:arnololo123
4 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 38748405
Perhaps you could use http://bassistance.de/jquery-plugins/jquery-plugin-validation/ this does all the work for you
0
 

Author Comment

by:arnololo123
ID: 38748441
Thanks but not an option
0
 
LVL 11

Accepted Solution

by:
madgino earned 2000 total points
ID: 38748682
try to use an 'if' instead of 'return' as the first return is exiting the javascript and disablebtn is never executing

 onclientclick="if (confirm('Do you want to save?') ) {disableBtn(this.id, 'Submitting...');} else {return false;}"
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38751701
What does
onclick="Bt_save_Click"

Open in new window

do?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question