By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

can i change an href in javascript?

P: n/a
I am new to javascript coding.

I am using some javascript code to change an image on an html page. I would
like the user to click on the image to bring them to another page. I need to
change an href to include an id value based on the image.

Here's the process:
1. select an image from a drop down list.
2. view the image on the same page.
3. click on the image to bring user to another page.

Here's my attempt at it:
function nextimg() {
txtString =
document.Topics.sel_val.options[document.Topics.sel_val.selectedIndex].value
document.image1.src = txtString.substring(txtString.lastIndexOf("&") + 1);
document.frmPic.href="details.asp?id=" & txtString;
}

I also think that txtString is not what I need. I believe it is a text
string (12345.jpg). So I will need to parse the string as well to get the
"12345".
Thanks for your help,

Irvin Amoraal. <><
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,

Instead of trying to change an href, try to do this:

<a href="javascript:gotoMyUrl()"><img src='...'></a>

Then define your gotoMyUrl() as:

var gNewLocation; // global variable that will be the new href
function gotoMyUrl()
{
location = gNewLocation;
}
Now whenever you want to change the href just change the 'gNewLocation'
variable.

HTH
Elias
"Irvin Amoraal" <ir***@rcabletv.on.com> wrote in message
news:vt************@corp.supernews.com...
I am new to javascript coding.

I am using some javascript code to change an image on an html page. I would like the user to click on the image to bring them to another page. I need to change an href to include an id value based on the image.

Here's the process:
1. select an image from a drop down list.
2. view the image on the same page.
3. click on the image to bring user to another page.

Here's my attempt at it:
function nextimg() {
txtString =
document.Topics.sel_val.options[document.Topics.sel_val.selectedIndex].value document.image1.src = txtString.substring(txtString.lastIndexOf("&") + 1); document.frmPic.href="details.asp?id=" & txtString;
}

I also think that txtString is not what I need. I believe it is a text
string (12345.jpg). So I will need to parse the string as well to get the
"12345".
Thanks for your help,

Irvin Amoraal. <><

Jul 20 '05 #2

P: n/a
Thanks for the idea, I'll give it a try.

Irvin.
"lallous" <la*****@lgwm.org> wrote in message
news:br************@ID-161723.news.uni-berlin.de...
Hello,

Instead of trying to change an href, try to do this:

<a href="javascript:gotoMyUrl()"><img src='...'></a>

Then define your gotoMyUrl() as:

var gNewLocation; // global variable that will be the new href
function gotoMyUrl()
{
location = gNewLocation;
}
Now whenever you want to change the href just change the 'gNewLocation'
variable.

HTH
Elias
"Irvin Amoraal" <ir***@rcabletv.on.com> wrote in message
news:vt************@corp.supernews.com...
I am new to javascript coding.

I am using some javascript code to change an image on an html page. I would
like the user to click on the image to bring them to another page. I need to
change an href to include an id value based on the image.

Here's the process:
1. select an image from a drop down list.
2. view the image on the same page.
3. click on the image to bring user to another page.

Here's my attempt at it:
function nextimg() {
txtString =

document.Topics.sel_val.options[document.Topics.sel_val.selectedIndex].value document.image1.src = txtString.substring(txtString.lastIndexOf("&") +

1);
document.frmPic.href="details.asp?id=" & txtString;
}

I also think that txtString is not what I need. I believe it is a text
string (12345.jpg). So I will need to parse the string as well to get the "12345".
Thanks for your help,

Irvin Amoraal. <><


Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.