?
Solved

Disable button and validate data in javascript

Posted on 2013-01-06
4
Medium Priority
?
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

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.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

719 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