Solved

use javascript to assign new href to button in .net app

Posted on 2014-01-28
5
555 Views
Last Modified: 2014-01-28
I'm working with a .net app and I need to re-assign the href attribute in a button. I can't mess with the .net code, but I can add all the javascript I want. However, so far I've had no luck.

Here's the button:

<a name="ctl00$ctl00$btnSubmit" language="javascript" href="javascript:{ClickOnce_ctl00_ctl00_btnSubmit();}" id="ctl00_ctl00_btnSubmit" style="float:left;">Save</a>

Here's how I'm trying to assign something new to href:

<script language="javascript">
 $(document).ready(function() {
 $("#ctl00_ctl00_btnSubmit").href="javascript:{alert('You clicked save!');}"
 }
 </script>

But nothing doing. Doesn't work. Can somebody help? Is there another method?
0
Comment
Question by:GessWurker
[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
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39816178
you're better off binding to the click() event of the button

<script language="javascript">
 $(document).ready(function() {
 $('#ctl00_ctl00_btnSubmit').on('click', function () {
            alert('You clicked save!');
  });
 }
 </script>
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39816187
if that doesn't work, then you can change the href like this:

$("#ctl00_ctl00_btnSubmit").attr("href", "javascript:{alert('You clicked save!") )
0
 

Author Comment

by:GessWurker
ID: 39816347
Hi Big Monty.

Neither option worked. No alert.
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39816375
try this, fixed a few typos:

<script language="javascript">
    $(document).ready(function () {
        $('#ctl00_ctl00_btnSubmit').attr("href", "javascript:{ alert('You clicked save!') }");
    });
 </script>
0
 

Author Comment

by:GessWurker
ID: 39816384
Excellent. Works!

Thanks!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

697 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