0

I'm using this script that takes an url and modifies it. It stores the new URL in a variable called #url and then it sets that variable as the href of a link.

It's changing the HREF however instead of printing the URL it's creating a link to the name of the variable: #url

This is the script:

    if(url.match(/http:\/\//))
    {
    url = url.substring(7);
    }
    if(url.match(/^www\./))
    {
    url = url.substring(4);
    }
    url = "www.chusmix.com/tests/?ref=" + url;
    $("#output").html(url);
    $("#url").val(url).focus().select();
    var yourElement = document.getElementById('test');
 yourElement.setAttribute('href', '#url');

I'm trying to make it work in JSFiddle, I just tried chaning the quotes but didn't work.

http://jsfiddle.net/Lisandro/JKxRg/4/

Thanks for any help

2
  • try removing your single quotes. the quotes are making it a string and not a call to the var. Commented Apr 27, 2011 at 5:07
  • I just tried without them on the variable and without them and with double quotes and neither did work =S Commented Apr 27, 2011 at 5:12

2 Answers 2

1

Remove the single quotes and no need to update the val if you going to change the attribute later.

 yourElement.setAttribute('href', url);
Sign up to request clarification or add additional context in comments.

Comments

0

yourElement.setAttribute('href', '#url');

'#url'?

You're printing a literal, so why are you surprised when you see a literal. jhanifen has given you the correct answer.

1 Comment

I have no idea how to use js it's my first site using it that's why. not mad. just telling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.