function

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

    function

    1. Here is my javascript

    <script language="JavaS cript">
    function link(linkname){
    strvar1 = linkname
    window.main.loc ation=""+strvar 1+".asp"
    }
    </script>

    2. Here is part of my code

    <img onclick="link(e ditoffice)" border="0" src="test_m1_i3 .png" />

    3. I don't know if the script is right or not, but I want to accomplish
    that once the image, that the main window location would go to
    editoffice.asp



  • Ivo

    #2
    Re: function

    "Samir" wrote[color=blue]
    > 1. Here is my javascript[/color]

    You don't describe your problem, but there are a couple of things that could
    do with improvement...
    [color=blue]
    > <script language="JavaS cript">[/color]
    Drop the language, use type instead:
    <script type="text/javascript">
    [color=blue]
    > function link(linkname){[/color]
    The word "link" is highly confusing, as there is already a string method and
    so many other things called "link". Name your function "mylink" or something
    else.
    [color=blue]
    > strvar1 = linkname[/color]
    You don't need to copy the variable here.
    Also, not necessary, but it is good practise to end each statement with ;
    [color=blue]
    > window.main.loc ation=""+strvar 1+".asp"[/color]
    The first (empty) string serves no purpose.
    [color=blue]
    > }
    > </script>
    >
    > 2. Here is part of my code
    >
    > <img onclick="link(e ditoffice)" border="0" src="test_m1_i3 .png" />[/color]
    You want "editoffice " as a string, so put it in quotes. Use single quotes
    (apostrophes) as the whole function call is already inside double quotes.
    [color=blue]
    > 3. I don't know if the script is right or not, but I want to accomplish
    > that once the image, that the main window location would go to
    > editoffice.asp
    >[/color]

    What happened when you tried it?

    Here is my version:
    <script type="text/javascript">
    function mylink(linkname ){
    window.main.loc ation=linkname+ ".asp";
    }
    </script>
    <img onclick="link(' editoffice')" border="0" src="test_m1_i3 .png" />
    Ivo


    Comment

    • Samir

      #3
      Re: function

      Thanks, I just needed the quotes all along.


      "Ivo" <no@thank.you > wrote in message
      news:40fc2a76$0 $148$18b6e80@ne ws.wanadoo.nl.. .[color=blue]
      > "Samir" wrote[color=green]
      > > 1. Here is my javascript[/color]
      >
      > You don't describe your problem, but there are a couple of things that[/color]
      could[color=blue]
      > do with improvement...
      >[color=green]
      > > <script language="JavaS cript">[/color]
      > Drop the language, use type instead:
      > <script type="text/javascript">
      >[color=green]
      > > function link(linkname){[/color]
      > The word "link" is highly confusing, as there is already a string method[/color]
      and[color=blue]
      > so many other things called "link". Name your function "mylink" or[/color]
      something[color=blue]
      > else.
      >[color=green]
      > > strvar1 = linkname[/color]
      > You don't need to copy the variable here.
      > Also, not necessary, but it is good practise to end each statement with ;
      >[color=green]
      > > window.main.loc ation=""+strvar 1+".asp"[/color]
      > The first (empty) string serves no purpose.
      >[color=green]
      > > }
      > > </script>
      > >
      > > 2. Here is part of my code
      > >
      > > <img onclick="link(e ditoffice)" border="0" src="test_m1_i3 .png" />[/color]
      > You want "editoffice " as a string, so put it in quotes. Use single quotes
      > (apostrophes) as the whole function call is already inside double quotes.
      >[color=green]
      > > 3. I don't know if the script is right or not, but I want to[/color][/color]
      accomplish[color=blue][color=green]
      > > that once the image, that the main window location would go to
      > > editoffice.asp
      > >[/color]
      >
      > What happened when you tried it?
      >
      > Here is my version:
      > <script type="text/javascript">
      > function mylink(linkname ){
      > window.main.loc ation=linkname+ ".asp";
      > }
      > </script>
      > <img onclick="link(' editoffice')" border="0" src="test_m1_i3 .png" />
      > Ivo
      >
      >[/color]


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: function

        "Samir" <Samir@hotmail. com> writes:
        [color=blue]
        > 1. Here is my javascript
        >
        > <script language="JavaS cript">[/color]

        Should be
        <script type="text/javascript">
        The "type" attribute is required in HTML 4, and it is always
        sufficient.
        [color=blue]
        > function link(linkname){
        > strvar1 = linkname
        > window.main.loc ation=""+strvar 1+".asp"[/color]

        This could be just:
        window.main.loc ation = linkname + ".asp";
        although I would prefer:
        frames["main"].location = linkname + ".asp";
        [color=blue]
        > }
        > </script>
        >
        > 2. Here is part of my code
        >
        > <img onclick="link(e ditoffice)" border="0" src="test_m1_i3 .png" />[/color]

        You want the string "editoffice " to be sent to the link function. However,
        what you have written is a variable called "editoffice ", and its value
        (if it had any) to be sent to the link function. Since the variable doesn't
        exist, this will just throw an error.

        Use:
        <img onclick="link(' editoffice');" style="border:n one;"
        src="test_m1_i3 .png" />


        (Are you sure you want to write XHTML?)

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...