2
var EventAddress=$(".EventAddress").text();
$(".EventDirectionLink a").attr("href", url + EventAddress);  

This is the jquery I am using to get the address value from the table cell and pass it to the map url as a query string but its not working? What am I doing wrong??

<div class="driving-directions-link">
<a href="http://maps.google.com/maps?q=">Get Direction</a>
</div>

<table cellpadding="10" class ="EventDetail">
    <tr>
        <td class="TableFields">Who Should Enroll?:</td>
        <td>Everyone 18 and older who would like to attend</td>
    </tr>
    <tr>
        <td class="TableFields">Location:</td>
        <td class="EventAddress">1300 Albany Street,Beech Grove ,IN</td>
    </tr>
</table>

5 Answers 5

4

Try this:

$('td.EventAddress').click(
    function(){
        $(".driving-directions-link a").attr("href", $(this).attr('href') + encodeURIComponent($(this).text)); 
    });

JS Fiddle demo.

Simplified the above a little, to avoid using the .attr() method twice (the second time unnecessarily):

$('td.EventAddress').click(function(){
    $(".driving-directions-link a").attr("href", function(i, h) {
        return h + encodeURIComponent($(this).text());
    });

JS Fiddle demo.

References:

Sign up to request clarification or add additional context in comments.

Comments

0
<div class="EventDirectionsLink">
<a href="http://maps.google.com/maps?q=">Get Direction</a>
</div>

<table cellpadding="10" class ="EventDetail">
    <tr>
        <td class="TableFields">Who Should Enroll?:</td>
        <td>Everyone 18 and older who would like to attend</td>
    </tr>
    <tr>
        <td class="TableFields">Location:</td>
        <td class="EventAddress">1300 Albany Street,Beech Grove ,IN</td>
    </tr>
</table>
var EventAddress=$(".EventAddress").text();
$(".EventDirectionsLink > a").attr("href", $('.EventDirectionsLink > a).attr('href') + EventAddress);  

Comments

0
$(".driving-directions-link > a").attr("href", "http://maps.google.com/maps?q=" + EventAddress);

Comments

0
var EventAddress = encodeURIComponent($(".EventAddress").text());
$(".EventDirectionLink a").attr("href", url + "q=" + EventAddress);  

Remember to decode the querystring before you use it.

Comments

0

I had a similar issue trying to add a querystring using:

$(this).attr("href", url + queryString);

It was adding the url but not the queryString.

I used the javascript concat method instead and this seemed to work:

var queryString = '?myVar=test';
//Replace the url with an additional query string
$(this).attr('href', $(this).attr('href').concat(queryString));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.