Solved

Disable button and validate data in javascript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

930 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

9 Experts available now in Live!

Get 1:1 Help Now