Solved

Disable button and validate data in javascript

Posted on 2013-01-06
4
469 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 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now