Forum Moderators: open

Message Too Old, No Replies

value in Href under Javascript

         

sfast

5:25 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



function (zip, name)
.
.
.
var html = "<b>" + name + "</b>" + '<a href="http://www.example.com?zipcode=zip>" click here </a>' ;

How do I pass the value of zip in the link. The link simply takes "zip" instead of its value.
Thanks

sfast

5:37 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



I tried it with this too. It doesnt display the value of zip.


var html = "<b>" + name + "</b> + "<br/>" + "<a href='http://www.example.com/Contact/retailDesc.php?zipcode='" + zip + "> click here </a>" ;

Any help is appreciated.

[edited by: jatar_k at 6:33 pm (utc) on Nov. 13, 2007]
[edit reason] please use example.com [/edit]

Dabrowski

5:55 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your second method should work, just a few mistakes with the quotation marks. Try breaking it down into more readable chunks:

var html = "<b>" + name + "</b>"; 
html += "<br/>";
html += "<a href='http://www.example.com/mypage.php?zipcode=" + zip + "> click here </a>";

I've highlighted the problems in the original line:

var html = "<b>" + name + "</b>
+ "
<br/>" + "<a href='http://www.example.com/mypage.php?zipcode=
'
" + zip + "> click here </a>";

If that still doesn't work, try simply:

alert( zip);

Which should popup and tell you what it thinks zip contains.

sfast

6:08 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



That was so nice of you.
You solved my problem.

Thanks a lot.

sfast

6:29 pm on Nov 13, 2007 (gmt 0)

10+ Year Member



One more problem,

I wanted to add - target="_blank" to the link.

html += "<a href=http://www.example.com?zipcode=" + zip + "&efinno="+ efin + " > <b>click here for Landmark information.</b> </a>";

Where do I add it?

The way I tried, it is adding target as a parameter too.

Thanks for all your help.

Dabrowski

10:52 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the problem you may be having here is with quotes within quotes.

Again, as we've got a large and complex string building up, let's break it down and make it more readable:

var href = "http://www.example.com/mypage.php"; 
href += "?zipcode="+ zip;
href += "&efinno="+ efin;

html += "<a href=
'
"+ href +"
'
target=
'
_blank
'
>"; 
html += "<b>click here for Landmark information.</b> </a>";

Note the quotation marks (I've highlighted them for you), the " is used around the JavaScript strings, and the ' around the HTML strings. If we used " all the time we'd prematurely end the JavaScript string.