Help - passing variable inside of src

I am familiar with php, but not so much with JavaScript.

I found a Google Gadget that basically gets driving directions that I want to use on my web site. Basically there are two text boxes: one for starting point, and one for destination. I want the destination box to be filled in based on a php variable that controls the location.

In a nut shell: I need to use a php variable $locgoomaps and pass it to the javascript and use it within the SRC tag. But, being very new to javascript, I am finding this to be quite frustrating.

  1. Currently this is being placed in the body of my page.

What I have been able to accomplish so far is this:

<SCRIPT LANGUAGE="javascript"><!--

<?php print("var resloc = " . $goomapsloc . " \
");?>
alert(resloc);

Php will write the java code so that I can easily pass the variable. I have the alert to test that it is passed correctly (and it is working).

Now, I still can’t figure out how to get my javascript ‘resloc’ variable to work with my src tag.

I have tried to do an src-“http://google.com. . blah. . blah. . loc=”+resloc+“&amp. . blah blah blah”

But this is not working. Nothing I have tried seems to work.

Here is the untouched src code that I need to pass my variable within:

src="http://www.gmodules.com/ig/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/108836475058194723393/driving_directions.xml&amp;up_from=&amp;up_to=

[COLOR=“Red”]

twin%20peaks%20blvd%2C%20san%20francisco

[/COLOR]

&amp;up_country=0&amp;synd=open&amp;w=400&amp;h=140&amp;title=Get+Directions&amp;lang=en&amp;country=CH&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"

The red text is what I need to be dynamic and replace with my variable, but I can’t seem to get this to come together . . where I pass the php variable to javascript and can use the new js variable in the src.

Any suggestions?

Thanks

Say in your HTML your src attribute was that for an image tag (same principal applies to other HTML tags like an image tag) e.g.

<script src=“” id=“yourScriptID”></script>

In your script, you could then dynamically set the value of the script src attribute like this:

var resloc = “twin%20peaks%20blvd%2C%20san%20francisco”;

var srcValue = “http://www.gmodules.com/ig/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/108836475058194723393/driving_directions.xml&amp;up_from=&amp;up_to=+ resloc + “&up_country=0&synd=open&w=400&h=140&title=Get+Directions&lang=en&country=CH&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js”

var yourScript = document.getElementById(‘yourScriptID’);
yourScript.src = resloc;