Dynamically adding url to link

How can I dynamically add the url 'http://www.sportingpulse.com/mobile/' to the start of these links. I want to display these basketball fixture links on our website www.saintsbc.com but don't want to have to manually enter the starting url each time. Our site currently uses php and javascript. So either will be ok.

      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223615"><div class="list-name">2012 Winter 18 Girls A</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223609"><div class="list-name">2012 Winter 16 Boys CR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223712"><div class="list-name">2012 Winter 18 Girls AR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223698"><div class="list-name">2012 Winter 16 Boys D</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223635"><div class="list-name">2012 Winter 18 Girls B</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223648"><div class="list-name">2012 Winter 16 Boys DR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223583"><div class="list-name">2012 Winter 16 Boys E</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223601"><div class="list-name">2012 Winter 23 Girls A</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223608"><div class="list-name">2012 Winter 18 Boys A</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223691"><div class="list-name">2012 Winter 23 Girls AR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223637"><div class="list-name">2012 Winter 18 Boys AR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223578"><div class="list-name">2012 Winter 18 Boys B</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223711"><div class="list-name">2012 Winter 23 Girls B</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223620"><div class="list-name">2012 Winter 18 Boys BR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223661"><div class="list-name">2012 Winter 18 Girls BR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223573"><div class="list-name">2012 Winter 18 Boys C</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223639"><div class="list-name">2012 Winter 23 Girls BR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223679"><div class="list-name">2012 Winter 23 Girls C</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223676"><div class="list-name">2012 Winter 20 Boys A</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223579"><div class="list-name">2012 Winter 20 Boys AR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223686"><div class="list-name">2012 Winter 23 Boys A</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223592"><div class="list-name">2012 Winter 20 Boys B</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223704"><div class="list-name">2012 Winter 23 Boys AR</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223662"><div class="list-name">2012 Winter 23 Boys B</div></a></li>
      <li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223685"><div class="list-name">2012 Winter 23 Boys BR</div></a></li>

Answers


if the <ul> or <ol> has an id perhaps do something like this with javascript

<ul id="mylinks">
<li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223615"><div class="list-name">2012 Winter 18 Girls A</div></a></li>
<li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223609"><div class="list-name">2012 Winter 16 Boys CR</div></a></li>
<li><a href="mobile.cgi?a=CF&amp;aID=2307&amp;cID=223712"><div class="list-name">2012 Winter 18 Girls AR</div></a></li>
</ul>

<script type="text/javascript">
var ul = document.getElementById("mylinks");
var lis = ul.getElementsByTagName("li"); 
var preurl = "http://www.sportingpulse.com/mobile/";

for( var i = 0; i < lis.length; i++ ) 
{ 
    lis.item(i).childNodes[0].href = preurl + lis.item(i).childNodes[0].href;
}
</script>

Worked it out... Even though the links above didn't specify my url host, they must auto add by default. So I adapted the code to use 'replace' to change my url host to the external one. Thanks again David.

<script type="text/javascript">
  var ul = document.getElementById("mylinks");
  var lis = ul.getElementsByTagName("li");
  var MYurl = "http://" + window.location.host + "/mobile/";
  var NEWurl = "http://www.sportingpulse.com/mobile/";
  for(var i = 0; i < lis.length; i++)
  {
    lis.item(i).childNodes[0].href = lis.item(i).childNodes[0].href.replace(MYurl, NEWurl);
  }
</script>

Need Your Help

Xcode Instruments - How to open the offending file for editing?

editor xcode5 instruments edit-in-place

I'm using a couple of third party libraries that appear to have memory leaks. Instruments highlight the offending lines of code on it's own window, but then I have to look myself in the Xcode editor

ByteBuffer.wrap came out unexpectedly

java android bytebuffer

I used ByteArray to create a new string, but the results came out unexpectedly. Here was my code