473,419 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

can i change an href in javascript?

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
2 9296
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christian Kusenbach | last post by:
Hello group! I've a problem with JavaScript and IMG-Objects. On my webpage I use a big image and several small images. If you click on a small image, it executes a JavaScript to change the...
3
by: bigoxygen | last post by:
Hi. I have a list that is similar to this: -Evaluation +test +test -Students +test I would like to change the "-" bullet only, but I cannot. My
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
3
by: Byron | last post by:
Hi, Javascript confuses me, so I usually limit myself to Dreamweaver's built-in scripts for stuff like imageswaps. But this time I'm trying to write something very simple myself. I do most of my...
5
by: Mel | last post by:
can someone post a simple javascript to change the text of the <href> for me ? thanks
15
by: Encapsulin | last post by:
Hello everybody. I'm trying to change src of quicktime embedded object with javascript: <html><body> <script language="JavaScript"> function Exchange() { document.qtvr.src = "sample2.pano";...
3
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have window.status="Moomin"; why doesn't the statusbar change?...
3
by: helraizer1 | last post by:
I have this code in JS function show_player() { document.mediaplayer1.style.visibility = "visible"; } function content(p, clip) { var mus = document.getElementById('music'); ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.