Solved

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

Posted on 2014-01-28
5
545 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
  • 3
  • 2
5 Comments
 
LVL 32

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 32

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 32

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now