dhcrusoe Posted March 23, 2009 Share Posted March 23, 2009 All, I'm working with a bit of pesky ASP code, and have a challenge I'd love some help with. The challenge is this: the ASP outputs one tag that I need to use twice. Here's a code example of what I have: <a id=newestuser href="http://www.test.com/user?name=tom"></a> and here's a code example of what I need: <a id=newestuser href="http://www.test.com/user?name=tom">tom</a> Either that, OR the javascript could simple read in the variable (tom) and output it twice - once into the href tag, and once into the link/title area of the <a> tag. Any thoughts/suggestions/ideas? (I'm a beginner JavaScripter -- sorry if it's a basic question, and thanks for your help!) --Dave Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 23, 2009 Share Posted March 23, 2009 while you could accomplish this with javascript, it would be MUCH MUCH better to do this on the server side. why can't use modify the ASP code to output it properly? Quote Link to comment Share on other sites More sharing options...
dhcrusoe Posted March 23, 2009 Author Share Posted March 23, 2009 Hey there -- I'm editing an installed version of DotNetNuke, and the modules that output the ASP are already compiled. So, there isn't much I can do to access everything, unless I were able to get into the source & recompile the module. So, in this case, I really (really) prefer to go the non-ideal JS route (even though, yes, it's FAR better to go with ASP). The basic problem I'm having is that, in the code, it won't let me repeat a tag twice, for instance: <asp:Label id="lblAuthor" Runat="server" cssclass="blog_Description"></asp:Label></TD> I'd far prefer that method, but nothing I've tried has worked.. Thanks! --Dave Quote Link to comment Share on other sites More sharing options...
Floydian Posted March 23, 2009 Share Posted March 23, 2009 Is the id for the anchor tag known to you before hand? i.e., can your js script know what id to look for? If so, a document.getElementById() and some slicing could extract the value of name= and insert it into the innerHTML. If you don't know id before hand, then you can use a getElementsByTagName type deal, and check them all to see if they have anything for their innerHTML. If they don't, then do the slicing/inserting. Hopefully that makes sense. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 23, 2009 Share Posted March 23, 2009 off the top of my head and untested: window.onload = function ( ) { var eles = document.getElementsByTagName('A'); var matches; for(var n=0;n < eles.length;n++){ if(eles[n].innerHTML == '' && matches = eles[n].href.match(/user?name=(.+)$/)) eles[n].innerHTML = matches[1]; } } Quote Link to comment Share on other sites More sharing options...
dhcrusoe Posted March 23, 2009 Author Share Posted March 23, 2009 Could we do a getelementbyID, and use the ID of the <A> tag instead? (Maybe that would make it more smooth, since there's only a single link this would impact?) --Dave Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 23, 2009 Share Posted March 23, 2009 oh...if there is only one: if(ele = document.getElementById('newestuser')){ if(matches = ele.href.match(/user?name=(.+)$/)) ele.innerHTML = matches[1]; } Quote Link to comment Share on other sites More sharing options...
dhcrusoe Posted March 23, 2009 Author Share Posted March 23, 2009 Hey all -- In the end, here's how it was resolved: <script type="text/javascript"> function createLink() { var link = document.getElementById('userlink').innerHTML; var newLink = 'http://www.test.com?user=' +link; window.location = newLink;} </script> <a href="javascript:createLink();" id="userlink">test</a> Thanks for all your help! --Dave Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.