• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

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

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
GessWurker
Asked:
GessWurker
  • 3
  • 2
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
if that doesn't work, then you can change the href like this:

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

Neither option worked. No alert.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try this, fixed a few typos:

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

Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now