using a string with object name to refrence object

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

    using a string with object name to refrence object

    I am new to JavaScript and I am currently having a problem that I can find
    no clear solution to. I have a series of button contained in a row. These
    rows are defined as follows:
    <tr> <!--This is Mondays row -->
    <td><button type="button" value="Monday" id="Monday" style="BACKGROU ND:
    yellow" onclick='Schedu leDay("Monday") '>Monday</button></td>
    <td><button type="button" value="M830" id="M830" style="BACKGROU ND:
    white">8:30</button></td>
    <td><button type="button" value="M900" id="M900" style="BACKGROU ND:
    white">9:00</button></td>
    <td><button type="button" value="M930" id="M930" style="BACKGROU ND:
    white">9:30</button></td>
    <td><button type="button" value="M1000" id="M1000" style="BACKGROU ND:
    white">10:00</button></td>
    <td><button type="button" value="M1030" id="M1030" style="BACKGROU ND:
    white">10:30</button></td>
    <td><button type="button" value="M1100" id="M1100" style="BACKGROU ND:
    white">11:00</button></td>
    <td><button type="button" value="M1130" id="M1130" style="BACKGROU ND:
    white">11:30</button></td>
    <td><button type="button" value="M1200" id="M1200" style="BACKGROU ND:
    white">12:00</button></td>
    <td><button type="button" value="M1230" id="M1230" style="BACKGROU ND:
    white">12:30</button></td>
    <td><button type="button" value="M100" id="M100" style="BACKGROU ND:
    white">1:00</button></td>
    <td><button type="button" value="M130" id="M130" style="BACKGROU ND:
    white">1:30</button></td>
    <td><button type="button" value="M200" id="M200" style="BACKGROU ND:
    white">2:00</button></td>
    <td><button type="button" value="M230" id="M230" style="BACKGROU ND:
    white">2:30</button></td>
    <td><button type="button" value="M300" id="M300" style="BACKGROU ND:
    white">3:00</button></td>
    <td><button type="button" value="M330" id="M330" style="BACKGROU ND:
    white">3:30</button></td>
    <td><button type="button" value="M400" id="M400" style="BACKGROU ND:
    white">4:00</button></td>
    <td><button type="button" value="M430" id="M430" style="BACKGROU ND: whi
    te">4:30</button></td>
    </tr>

    The ScheduleDay function displays the gets the value of a series of radio
    buttons. The problem is that the value is a string corresponding to the ID
    attribute of the button ( I have tried the name attribute to). I want to
    use this string to change the background color of the button using a
    function prototyped likeColorPeriod Btn(Btnname,Col or). I am getting very
    frustrated any help would be appreciated.


  • ManoDestra

    #2
    Re: using a string with object name to refrence object

    If you are using Internet Explorer (5 onwards, I think), then you can use
    the following...

    function changeElement(s trId) {
    document.getEle mentById(strId) .style = "background:yel low";
    }

    Alternatively, use a style sheet, then do...

    function changeElement(s trId) {
    document.getEle mentById(strId) .className = strYourClassNam e;
    }

    When passing values to the function containing the above you could use
    changeElement(t his.id) when passing from an event from the specific element
    you wish to change.

    Hope some of this ramble makes sense to you!

    Peter.

    "Charles Russell" <cerjr@surewest .net> wrote in message
    news:vhp39tp3sp 7cfb@corp.super news.com...[color=blue]
    > I am new to JavaScript and I am currently having a problem that I can[/color]
    find[color=blue]
    > no clear solution to. I have a series of button contained in a row. These
    > rows are defined as follows:
    > <tr> <!--This is Mondays row -->
    > <td><button type="button" value="Monday" id="Monday"[/color]
    style="BACKGROU ND:[color=blue]
    > yellow" onclick='Schedu leDay("Monday") '>Monday</button></td>
    > <td><button type="button" value="M830" id="M830" style="BACKGROU ND:
    > white">8:30</button></td>
    > <td><button type="button" value="M900" id="M900" style="BACKGROU ND:
    > white">9:00</button></td>
    > <td><button type="button" value="M930" id="M930" style="BACKGROU ND:
    > white">9:30</button></td>
    > <td><button type="button" value="M1000" id="M1000" style="BACKGROU ND:
    > white">10:00</button></td>
    > <td><button type="button" value="M1030" id="M1030" style="BACKGROU ND:
    > white">10:30</button></td>
    > <td><button type="button" value="M1100" id="M1100" style="BACKGROU ND:
    > white">11:00</button></td>
    > <td><button type="button" value="M1130" id="M1130" style="BACKGROU ND:
    > white">11:30</button></td>
    > <td><button type="button" value="M1200" id="M1200" style="BACKGROU ND:
    > white">12:00</button></td>
    > <td><button type="button" value="M1230" id="M1230" style="BACKGROU ND:
    > white">12:30</button></td>
    > <td><button type="button" value="M100" id="M100" style="BACKGROU ND:
    > white">1:00</button></td>
    > <td><button type="button" value="M130" id="M130" style="BACKGROU ND:
    > white">1:30</button></td>
    > <td><button type="button" value="M200" id="M200" style="BACKGROU ND:
    > white">2:00</button></td>
    > <td><button type="button" value="M230" id="M230" style="BACKGROU ND:
    > white">2:30</button></td>
    > <td><button type="button" value="M300" id="M300" style="BACKGROU ND:
    > white">3:00</button></td>
    > <td><button type="button" value="M330" id="M330" style="BACKGROU ND:
    > white">3:30</button></td>
    > <td><button type="button" value="M400" id="M400" style="BACKGROU ND:
    > white">4:00</button></td>
    > <td><button type="button" value="M430" id="M430" style="BACKGROU ND:[/color]
    whi[color=blue]
    > te">4:30</button></td>
    > </tr>
    >
    > The ScheduleDay function displays the gets the value of a series of radio
    > buttons. The problem is that the value is a string corresponding to the[/color]
    ID[color=blue]
    > attribute of the button ( I have tried the name attribute to). I want to
    > use this string to change the background color of the button using a
    > function prototyped likeColorPeriod Btn(Btnname,Col or). I am getting very
    > frustrated any help would be appreciated.
    >
    >[/color]


    Comment

    • Dr John Stockton

      #3
      Re: using a string with object name to refrence object

      JRS: In article <KA1Ta.957$%D3. 320017@newsfep2-gui.server.ntli .net>,
      seen in news:comp.lang. javascript, ManoDestra <manodestra.sof tware@ntlwo
      rld.com> posted at Tue, 22 Jul 2003 03:46:42 :-
      [color=blue]
      >If you are using Internet Explorer (5 onwards, I think), then you can use
      >the following...
      >
      >function changeElement(s trId) {
      > document.getEle mentById(strId) .style = "background:yel low";
      >}[/color]


      That's not right, under default assumptions.

      It is OK if we assume that the only person reading the page is its
      author (I have a few like that); but in the World-Wide Web, which is the
      default assumption here, it is the reader's browser that matters, not
      the author's. Many authors do not think of that.

      The proportion who are using browsers compatible with IE5 is large, but
      it is not unity.



      Before answering here, you should read and understand the regularly-
      posted FAQ, linked below; section 2.3 in particular.

      Look at the posts in this group, ignoring yours and mine; you will see
      that the more intelligent users predominantly comply with paragraph 5 of
      2.3, and in particular sentence 6 thereof. Responses should follow
      trimmed quotes.



      Jim - FAQ 2.3 para 2 sentence 2 last word should be words.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

      Comment

      Working...