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?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.