Solved

Disable button and validate data in javascript

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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…

735 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