string vs object

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

    string vs object

    If I have:

    <a href="javascrip t:myfunct('cool _links')" id="cool_links" >

    and I refer to it as:
    function myfunct(mylink)
    {
    document.getEle mentById[mylink]
    }

    then it is NOT reffered to as an object. I have to change my link to :
    <a href="javascrip t:myfunct(cool_ links)" id="cool_links" >

    Notice I took the tick marks out. I'm not telling u anything new here. The
    question I have is how can I include the link id as:
    <a href="javascrip t:myfunct('cool _links')" id="cool_links" > with the tick
    marks and then refer to it as an object?

    Mike


  • Ivo

    #2
    Re: string vs object


    "Michael Hill" <hillmw@charter .net> wrote in message
    news:vns8tsnk4f 0b60@corp.super news.com...[color=blue]
    > If I have:
    >
    > <a href="javascrip t:myfunct('cool _links')" id="cool_links" >[/color]

    Try this:
    <a href="noscript. html" onclick="myfunc t(this);return false"
    id="cool_links" >

    See the word "this" (without quotes)? This is a reserved word in javascript,
    referring to whatever element it finds itself in, in this case an <a> tag.
    This will be interpreted as an object variable by the same function that you
    wrote.
    Notice also that using the javascript: protocol in href attribute is not a
    good idea as it is not well supported by browsers. The href should be a
    valid link to a document for script-impaired users. The onclick will handle
    the javascript (no need for setting the protocol there), and if it return
    false the href will be ignored.
    Ivo

    [color=blue]
    > and I refer to it as:
    > function myfunct(mylink)
    > {
    > document.getEle mentById[mylink]
    > }
    >
    > then it is NOT reffered to as an object. I have to change my link to :
    > <a href="javascrip t:myfunct(cool_ links)" id="cool_links" >
    >
    > Notice I took the tick marks out. I'm not telling u anything new here. The
    > question I have is how can I include the link id as:
    > <a href="javascrip t:myfunct('cool _links')" id="cool_links" > with the tick
    > marks and then refer to it as an object?
    >
    > Mike
    >
    >[/color]


    Comment

    • Michael Hill

      #3
      Re: string vs object

      yes the myfunct(this) is the same as if I used myfunct(cool_li nks).

      Reason that I like somehow to store the string is that I created a hidden
      variable like:
      <input type='hidden' name='myhidden' value=''>

      and would like to store the name of the object there so I can use it later
      in javascript processing. If not I have to pass the object around through
      each javascript function.

      I dont think I can store the object there can I?

      Mike


      "Ivo" <no@thank.you > wrote in message
      news:3f7e2bc3$0 $440$1b62eedf@n ews.wanadoo.nl. ..[color=blue]
      >
      > "Michael Hill" <hillmw@charter .net> wrote in message
      > news:vns8tsnk4f 0b60@corp.super news.com...[color=green]
      > > If I have:
      > >
      > > <a href="javascrip t:myfunct('cool _links')" id="cool_links" >[/color]
      >
      > Try this:
      > <a href="noscript. html" onclick="myfunc t(this);return false"
      > id="cool_links" >
      >
      > See the word "this" (without quotes)? This is a reserved word in[/color]
      javascript,[color=blue]
      > referring to whatever element it finds itself in, in this case an <a> tag.
      > This will be interpreted as an object variable by the same function that[/color]
      you[color=blue]
      > wrote.
      > Notice also that using the javascript: protocol in href attribute is not a
      > good idea as it is not well supported by browsers. The href should be a
      > valid link to a document for script-impaired users. The onclick will[/color]
      handle[color=blue]
      > the javascript (no need for setting the protocol there), and if it return
      > false the href will be ignored.
      > Ivo
      >
      >[color=green]
      > > and I refer to it as:
      > > function myfunct(mylink)
      > > {
      > > document.getEle mentById[mylink]
      > > }
      > >
      > > then it is NOT reffered to as an object. I have to change my link to :
      > > <a href="javascrip t:myfunct(cool_ links)" id="cool_links" >
      > >
      > > Notice I took the tick marks out. I'm not telling u anything new here.[/color][/color]
      The[color=blue][color=green]
      > > question I have is how can I include the link id as:
      > > <a href="javascrip t:myfunct('cool _links')" id="cool_links" > with the[/color][/color]
      tick[color=blue][color=green]
      > > marks and then refer to it as an object?
      > >
      > > Mike
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Ivo

        #4
        Re: string vs object

        "Michael Hill" <hillmw@charter .net> wrote in message
        news:vnse175u59 8k23@corp.super news.com...[color=blue]
        > "Ivo" <no@thank.you > wrote in message
        > news:3f7e2bc3$0 $440$1b62eedf@n ews.wanadoo.nl. ..[color=green]
        > >
        > > "Michael Hill" <hillmw@charter .net> wrote in message
        > > news:vns8tsnk4f 0b60@corp.super news.com...[color=darkred]
        > > > If I have:
        > > >
        > > > <a href="javascrip t:myfunct('cool _links')" id="cool_links" >
        > > > and I refer to it as:
        > > > function myfunct(mylink)
        > > > {
        > > > document.getEle mentById[mylink]
        > > > }
        > > >
        > > > The question I have is how can I include the link id as:
        > > > <a href="javascrip t:myfunct('cool _links')" id="cool_links" >
        > > > with the tickmarks and then refer to it as an object?
        > > >
        > > > Mike[/color]
        > >
        > > Try this:
        > > <a href="noscript. html" onclick="myfunc t(this);return false"
        > > id="cool_links" >
        > >
        > > See the word "this" (without quotes)? This is a reserved word in[/color]
        > javascript,[color=green]
        > > referring to whatever element it finds itself in, in this case an <a>[/color][/color]
        tag.[color=blue][color=green]
        > > This will be interpreted as an object variable by the same function that[/color]
        > you[color=green]
        > > wrote.
        > > Notice also that using the javascript: protocol in href attribute is not[/color][/color]
        a[color=blue][color=green]
        > > good idea as it is not well supported by browsers. The href should be a
        > > valid link to a document for script-impaired users. The onclick will[/color]
        > handle[color=green]
        > > the javascript (no need for setting the protocol there), and if it[/color][/color]
        return[color=blue][color=green]
        > > false the href will be ignored.
        > > Ivo
        > >
        > >[/color]
        > yes the myfunct(this) is the same as if I used myfunct(cool_li nks).
        >
        > Reason that I like somehow to store the string is that I created a hidden
        > variable like:
        > <input type='hidden' name='myhidden' value=''>
        >
        > and would like to store the name of the object there so I can use it later
        > in javascript processing. If not I have to pass the object around through
        > each javascript function.
        >
        > I dont think I can store the object there can I?
        >
        > Mike
        >[/color]

        Please put your reply at the bottom. The Usenet convention is to have the
        answer follow the question, like in real life.

        The variable this.id can be passed around separately if you find the object
        too clumsy. I tried the above <a> tag with this function myfunct(mylink) {
        alert(mylink); // [object]
        alert(typeof mylink); // object
        alert(mylink.id ); // cool_links
        alert(typeof mylink.id); // string
        }

        Btw, if the only purpose of the hidden input field is to store a string, why
        not use a global variable? Global variables can even hold whole objects, so
        you can check its offsetHeight or whatever you like whenever you like.
        Ivo


        Comment

        • Richard Cornford

          #5
          Re: string vs object

          "Michael Hill" <hillmw@charter .net> wrote in message
          news:vns8tsnk4f 0b60@corp.super news.com...[color=blue]
          > If I have:
          >
          ><a href="javascrip t:myfunct('cool _links')" id="cool_links" >[/color]

          <quote cite="http://jibbering.com/faq/#FAQ4_24">
          I have <a href="javascrip t:somefunction( )"> what ... ?
          </quote>
          [color=blue]
          >and I refer to it as:
          >function myfunct(mylink)
          >{
          > document.getEle mentById[mylink][/color]
          <snip>

          JavaScript uses square brackets in bracket notation property accessors,
          for indexing arrays and to define array literals. Parentheses are used
          for function calls. As you have it, this line of code is attempting to
          read a property of the document.getEle mentById function. Because
          JavaScript functions are objects this is feasible but the
          document.getEle mentById function will not normally have a property with
          a name that corresponds with the toString value of the myLink parameter
          of the myfunct function.

          Try:-
          document.getEle mentById(mylink );
          - instead. However, this function does not do anything with the result
          of the function call so there is probably no point in calling the
          function at all.

          Note that getElementById retrieves references to DOM elements with the
          corresponding ID attribute. Elements that only have NAME attributes must
          be accessed by other means.

          Richard.


          Comment

          • Hendrik Krauss

            #6
            Re: string vs object

            [75 lines of quotation skipped][color=blue]
            > Please put your reply at the bottom. The Usenet convention is to have the
            > answer follow the question, like in real life.[/color]

            Like the famous chunk of FAQ that explains this :)

            A: No.
            Q: Should I post my reply above the quoted text?

            Related to that (sorry if I'm impolite, but I have to say it): last time I checked the Usenet convention was
            also to *edit your followups*. Please don't add 14 lines of content to 75 lines of redundant, badly-wrapped,
            ugly-to-read quotations that are in no direct relation to what you're saying.

            Didn't mean to insult you--and I don't claim I'm a guru of Usenet etiquette, either ... but let's keep trying.

            Best regards
            Hendrik Krauss

            Comment

            • Michael Hill

              #7
              Re: string vs object

              >[color=blue]
              > Try:-
              > document.getEle mentById(mylink );
              > - instead. However, this function does not do anything with the result
              > of the function call so there is probably no point in calling the
              > function at all.[/color]

              This works. I had a string that I fed like:

              mylink='my_link _id';
              var tableLeft = getOffsetLeft( document.getEle mentById(mylink ) );

              function getOffsetLeft(e l)
              {
              var ol = el.offsetLeft;
              while ( ( el = el.offsetParent ) != null )
              {
              ol += el.offsetLeft;
              }
              return ol;
              }

              I got the proper value of the offset. Thanks for everyones help.


              Comment

              • Dr John Stockton

                #8
                Re: string vs object

                JRS: In article <3f7ebeee$0$124 74$9b622d9e@new s.freenet.de>, seen in
                news:comp.lang. javascript, Hendrik Krauss <usenet@removet his.hendrik-
                krauss.andthat. de> posted at Sat, 4 Oct 2003 14:37:03 :-[color=blue]
                >
                >Related to that (sorry if I'm impolite, but I have to say it): last time I
                >checked the Usenet convention was
                >also to *edit your followups*. Please don't add 14 lines of content to 75 lines
                >of redundant, badly-wrapped,
                >ugly-to-read quotations that are in no direct relation to what you're saying.[/color]

                A further convention that you yourself have ignored is to set the right
                margin at (about) 72 characters, at least for text in paragraphs. This
                is, in part, for display in traditional-sized windows; but it is also
                helpful to the human eye - see any book or magazine.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
                Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
                Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
                No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                Comment

                Working...