Need help converting an input onclick to a hyperlink

I'm trying to convert an input type=submit to an anchor/hyperlink that performs the same action.

I'm close, but it still doesn't seem to be right.   Any help?
<input type="submit" class="button" id="ctl00_cntMain_UC_ProductView_UC_ProductVersions_rptRows_ctl01_UC_AddToBasketQty2_btnAdd" onclick="ShowAddToBasketPopup(2000);" value="Add" name="ctl00$cntMain$UC_ProductView$UC_ProductVersions$rptRows$ctl01$UC_AddToBasketQty2$btnAdd"  />

<a href="javascript:void(0)" onclick="document.aspnetForm.submit();ShowAddToBasketPopup(2000);window.open('http://www.yahoo.com');">Add</a>

Open in new window

saturationAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Your link is similar to this
<a href="javascript:void(0)" onclick="document.aspnetForm.submit()">Add</a>

Open in new window

because you submit the page, it don't wait to run the code after

If possible try like this :
<a href="javascript:void(0)" onclick="ShowAddToBasketPopup(2000);window.open('http://www.yahoo.com');document.aspnetForm.submit();">Add</a>

Open in new window

0
DesignbyonyxCommented:
If you are using .NET form controls, why not use a link button:

<asp:LinkButton ID="lbSomeButton" runat="server">Submit</asp:LinkButton>

Open in new window


Or, you could just style the button as a link.  Here's a better description than I could give:

http://www.xlevel.org.uk/post/How-to-style-a-HTML-Form-button-as-a-Hyperlink-using-CSS.aspx
0
saturationAuthor Commented:
Tried, can't get either to work the right way.  I have more information

I have more information....It seems that the submission of the form by a particular button with $ctl01 will save that record.   However, if I try to use it as a link name, it doesn't work--because links don't get submitted as form values.   I guess then, my question is, is it possible to pick up the name of the submit button when the form is submitted?   If so, I was unaware of this.   Let me know.


<input type="submit" name="ctl00$cntMain$UC_ProductView$UC_ProductVersions$rptRows$ctl01$UC_AddToBasketQty2$btnAdd" value="Add 100" onclick="ShowAddToBasketPopup(2000);" id="ctl00_cntMain_UC_ProductView_UC_ProductVersions_rptRows_ctl00_UC_AddToBasketQty2_btnAdd" class="button" />

<a href="javascript:void(0)" onclick="document.aspnetForm.submit();ShowAddToBasketPopup(2000);window.open('http://www.yahoo.com');" name="ctl00$cntMain$UC_ProductView$UC_ProductVersions$rptRows$ctl01$UC_AddToBasketQty2$btnAdd" id="ctl00_cntMain_UC_ProductView_UC_ProductVersions_rptRows_ctl01_UC_AddToBasketQty2_btnAdd" target="_blank">Test LINK</a>
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

DesignbyonyxCommented:
I'm not really sure what you are trying to accomplish.  Maybe if you could describe your goal, we can help you achieve that goal.  Looking at your code, you are going down the wrong path.  Please describe the "use case" like this:

User visits page
User fills out form
User clicks submit.
 - Data saved to DB
 - New window opens with Yahoo

0
saturationAuthor Commented:
User visits page:   working
User clicks "add" to one of two rows:   working if they use the <input type=submit> code above
-data saved to the DB:  working

not working:   i need to launch a new window/URL when they submit the button, but still have the existing window do what it normally does.
0
DesignbyonyxCommented:
ahh.  So are you cool with keeping the button?  I suggest you keep the button, and if it needs to look like a link, you can make it look like a link.

So there are 2 ways you can do this.  This assumes that there is a javascript function called "ShowPopUp":

1) In the code behind, add something like this to your Page_Load:

btnAdd.Attributes.Add('onclick', 'ShowPopUp();');

2) On the client side using javascript (this is the option I would choose, personally)

var btnAdd = document.getElementByID('<%= btnAdd.ClientID %>');
btnAdd.onclick = ShowPopUp;
0
DesignbyonyxCommented:
Doh!  Typo in my javascript.  Should be getDocumentById  (with a lowercase 'Id'):

var btnAdd = document.getElementById('<%= btnAdd.ClientID %>');
btnAdd.onclick = ShowPopUp;  

And since I'm here, you could do something like this too:

var btnAdd = document.getElementById('<%= btnAdd.ClientID %>');
btnAdd.onclick = function() {
  // Do some javascript coolness here before calling popup function
  alert('Something cool is about to happen');
  ShowPopUp();
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saturationAuthor Commented:
Thanks, that seems like it will work, but when I popped in the code, I get the error below on the line of code below:

"error BC30451: Name 'btnAdd' is not declared. "
var btnAdd = document.getElementById('<%= btnAdd.ClientID %>');

Ideas?
0
DesignbyonyxCommented:
Hmmm, so your aspx page should look something like:

(over simplified to make the point)
<script type="text/javascript">
var btnAdd = document.getElementById('<%= btnAdd.ClientID %>');
btnAdd.onclick = ShowPopUp;
</script>

<asp:Button ID="btnAdd" runat="server" />

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.