can i change an href in javascript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Irvin Amoraal

    #1

    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.option s[document.Topics .sel_val.select edIndex].value
    document.image1 .src = txtString.subst ring(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. <><


  • lallous

    #2
    Re: can i change an href in javascript?

    Hello,

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

    <a href="javascrip t: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" <irvin@rcabletv .on.com> wrote in message
    news:vthhvkbg47 fv05@corp.super news.com...[color=blue]
    > I am new to javascript coding.
    >
    > I am using some javascript code to change an image on an html page. I[/color]
    would[color=blue]
    > like the user to click on the image to bring them to another page. I need[/color]
    to[color=blue]
    > 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 =
    >[/color]
    document.Topics .sel_val.option s[document.Topics .sel_val.select edIndex].value[color=blue]
    > document.image1 .src = txtString.subst ring(txtString. lastIndexOf("&" ) +[/color]
    1);[color=blue]
    > 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. <><
    >
    >[/color]


    Comment

    • Irvin Amoraal

      #3
      Re: can i change an href in javascript?

      Thanks for the idea, I'll give it a try.

      Irvin.


      "lallous" <lallous@lgwm.o rg> wrote in message
      news:bral54$1bn vb$1@ID-161723.news.uni-berlin.de...[color=blue]
      > Hello,
      >
      > Instead of trying to change an href, try to do this:
      >
      > <a href="javascrip t: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" <irvin@rcabletv .on.com> wrote in message
      > news:vthhvkbg47 fv05@corp.super news.com...[color=green]
      > > I am new to javascript coding.
      > >
      > > I am using some javascript code to change an image on an html page. I[/color]
      > would[color=green]
      > > like the user to click on the image to bring them to another page. I[/color][/color]
      need[color=blue]
      > to[color=green]
      > > 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 =
      > >[/color]
      >[/color]
      document.Topics .sel_val.option s[document.Topics .sel_val.select edIndex].value[color=blue][color=green]
      > > document.image1 .src = txtString.subst ring(txtString. lastIndexOf("&" ) +[/color]
      > 1);[color=green]
      > > 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[/color][/color]
      the[color=blue][color=green]
      > > "12345".
      > >
      > >
      > > Thanks for your help,
      > >
      > > Irvin Amoraal. <><
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...