1 Replies - 4437 Views - Last Post: 02 November 2012 - 03:01 AM

#1 Bocard  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 223
  • Joined: 24-September 08

Problem setting href attribute

Posted 06 September 2012 - 07:32 AM

Hi guys,

I have a link that needs to update automatically. Whatever url i have in an input text i want that value to be the href value for a link.

This is what i have right now:
function changePreviewUrl(event)
            $('.theForm:eq(' + event.data.i + ') [name=previewUrlLink]').attr('href', "http://"+ $('.theForm:eq(' + event.data.i + ') [name=previewUrl]').val());

The link changes dynamically as it is suposed to but if i have in my input text: "http://www.google.com". The value i get in my href attribute is: "http//www.google.com".
Whatever I tried, i couldn get the colon (after http it's supposed to be a colon before the "//").

Any ideas why this happens and how can i fix it?

Thank you very much for your time and help.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem setting href attribute

#2 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 442
  • Joined: 28-July 09

Re: Problem setting href attribute

Posted 02 November 2012 - 03:01 AM


I tried to replicate the bug you are seeing but it works fine for me every time.

<script type="text/javascript">
		$(document).on('click', '#button', function()
			$('a').attr('href', "http://"+ $('#test').val());

<input type="text" id="test"/>
<input type="button" id="button"/>
<a href="">My link</a>

Could you perhaps post your entire application code or a link to the development environment the bug is occurring in? Also which browser are you seeing the issue in?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1