[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-01-28
5
Medium Priority
?
575 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

656 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