Set cell text dynamically?

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

    Set cell text dynamically?

    I have a table containing this cell -

    <td id="section5" height="37" align="center"
    class="cellbott omborder">
    System Data Maintainance
    </td>

    How can I read the contents of this cell & set them to something else
    dynamically?

    The idea is to append an "*" when user had changed some data, so the
    following function is called from a controls onchange() event. This works
    BUT loses the formattting from the class="cellbott omborder" atrribute -

    function changedDetails( )
    {
    var titleCell = getElement('sec tion5')
    var titleText = titleCell.inner Text;
    var pos = titleText.index Of("*");

    if(pos<0)
    titleCell.inner Text = titleText + "*";
    }

    Probably very simple!

    thanks

    harry


  • McKirahan

    #2
    Re: Set cell text dynamically?

    "harry" <spammemothers@ yahoo.co.uk> wrote in message
    news:pKb6d.1519 85$hZ3.84514@fe 2.news.blueyond er.co.uk...[color=blue]
    > I have a table containing this cell -
    >
    > <td id="section5" height="37" align="center"
    > class="cellbott omborder">
    > System Data Maintainance
    > </td>
    >
    > How can I read the contents of this cell & set them to something else
    > dynamically?
    >
    > The idea is to append an "*" when user had changed some data, so the
    > following function is called from a controls onchange() event. This works
    > BUT loses the formattting from the class="cellbott omborder" atrribute -
    >
    > function changedDetails( )
    > {
    > var titleCell = getElement('sec tion5')
    > var titleText = titleCell.inner Text;
    > var pos = titleText.index Of("*");
    >
    > if(pos<0)
    > titleCell.inner Text = titleText + "*";
    > }
    >
    > Probably very simple!
    >
    > thanks
    >
    > harry
    >[/color]

    The following retains the style of the cell (for me):

    <html>
    <head>
    <title>celltext .htm</title>
    <script type="text/javascript">
    function changedDetails( ) {
    var titleCell = document.getEle mentById("secti on5");
    var titleText = titleCell.inner Text;
    var pos = titleText.index Of("*");
    if (pos<0) titleCell.inner Text = titleText + "*";
    }
    </script>
    <style type="text/css">
    ..cellbottombor der { font-size:24pt }
    </style>
    </head>
    <body>
    <table>
    <tr>
    <td id="section5" height="37" align="center" class="cellbott omborder">
    System Data Maintainance
    </td>
    </tr>
    </table>
    <br>
    <input type="button" value="changedD etails()" onclick="change dDetails()">
    </body>
    </html>


    Comment

    • harry

      #3
      Re: Set cell text dynamically?

      Thanks, this works fine but puzzled as to why mine doesn't?

      Your code looks identical to mine (except getElement() which does the
      document.getEle mentById() bit!). Also my stylesheet is attached not inline -
      is this the reason of have I missed something else?

      thanks

      harry


      "McKirahan" <News@McKirahan .com> wrote in message
      news:3Tb6d.1294 33$D%.102345@at tbi_s51...[color=blue]
      > "harry" <spammemothers@ yahoo.co.uk> wrote in message
      > news:pKb6d.1519 85$hZ3.84514@fe 2.news.blueyond er.co.uk...[color=green]
      > > I have a table containing this cell -
      > >
      > > <td id="section5" height="37" align="center"
      > > class="cellbott omborder">
      > > System Data Maintainance
      > > </td>
      > >
      > > How can I read the contents of this cell & set them to something else
      > > dynamically?
      > >
      > > The idea is to append an "*" when user had changed some data, so the
      > > following function is called from a controls onchange() event. This[/color][/color]
      works[color=blue][color=green]
      > > BUT loses the formattting from the class="cellbott omborder" atrribute -
      > >
      > > function changedDetails( )
      > > {
      > > var titleCell = getElement('sec tion5')
      > > var titleText = titleCell.inner Text;
      > > var pos = titleText.index Of("*");
      > >
      > > if(pos<0)
      > > titleCell.inner Text = titleText + "*";
      > > }
      > >
      > > Probably very simple!
      > >
      > > thanks
      > >
      > > harry
      > >[/color]
      >
      > The following retains the style of the cell (for me):
      >
      > <html>
      > <head>
      > <title>celltext .htm</title>
      > <script type="text/javascript">
      > function changedDetails( ) {
      > var titleCell = document.getEle mentById("secti on5");
      > var titleText = titleCell.inner Text;
      > var pos = titleText.index Of("*");
      > if (pos<0) titleCell.inner Text = titleText + "*";
      > }
      > </script>
      > <style type="text/css">
      > .cellbottombord er { font-size:24pt }
      > </style>
      > </head>
      > <body>
      > <table>
      > <tr>
      > <td id="section5" height="37" align="center" class="cellbott omborder">
      > System Data Maintainance
      > </td>
      > </tr>
      > </table>
      > <br>
      > <input type="button" value="changedD etails()" onclick="change dDetails()">
      > </body>
      > </html>
      >
      >[/color]


      Comment

      • McKirahan

        #4
        Re: Set cell text dynamically?

        "harry" <spammemothers@ yahoo.co.uk> wrote in message
        news:27c6d.1522 03$hZ3.96707@fe 2.news.blueyond er.co.uk...[color=blue]
        > Thanks, this works fine but puzzled as to why mine doesn't?
        >
        > Your code looks identical to mine (except getElement() which does the
        > document.getEle mentById() bit!). Also my stylesheet is attached not[/color]
        inline -[color=blue]
        > is this the reason of have I missed something else?
        >
        > thanks
        >
        > harry[/color]

        Probably the "document.getEl ementById()".

        I got an "Object expected" error when I used your "getElement ()".


        Comment

        • harry

          #5
          Re: Set cell text dynamically?

          spooky, all getElement() does is this -

          function getElement(id)
          {
          return document.getEle mentById(id);
          }

          my app is for my company's intranet & the target platform is IE 5.5 (sp2) &
          no other.

          any other ideas?

          thanks

          "McKirahan" <News@McKirahan .com> wrote in message
          news:Zoc6d.1233 03$MQ5.100673@a ttbi_s52...[color=blue]
          > "harry" <spammemothers@ yahoo.co.uk> wrote in message
          > news:27c6d.1522 03$hZ3.96707@fe 2.news.blueyond er.co.uk...[color=green]
          > > Thanks, this works fine but puzzled as to why mine doesn't?
          > >
          > > Your code looks identical to mine (except getElement() which does the
          > > document.getEle mentById() bit!). Also my stylesheet is attached not[/color]
          > inline -[color=green]
          > > is this the reason of have I missed something else?
          > >
          > > thanks
          > >
          > > harry[/color]
          >
          > Probably the "document.getEl ementById()".
          >
          > I got an "Object expected" error when I used your "getElement ()".
          >
          >[/color]


          Comment

          • McKirahan

            #6
            Re: Set cell text dynamically?

            "harry" <spammemothers@ yahoo.co.uk> wrote in message
            news:Gud6d.1529 15$hZ3.57543@fe 2.news.blueyond er.co.uk...[color=blue]
            > spooky, all getElement() does is this -
            >
            > function getElement(id)
            > {
            > return document.getEle mentById(id);
            > }
            >
            > my app is for my company's intranet & the target platform is IE 5.5 (sp2)[/color]
            &[color=blue]
            > no other.
            >
            > any other ideas?
            >
            > thanks[/color]

            I didn't know you had a function call "getElement(id) "

            This works for me.

            <html>
            <head>
            <title>celltext .htm</title>
            <script type="text/javascript">
            function getElement(id) {
            return document.getEle mentById(id);
            }
            function changedDetails( ) {
            var titleCell = getElement("sec tion5");
            // var titleCell = document.getEle mentById("secti on5");
            var titleText = titleCell.inner Text;
            var pos = titleText.index Of("*");
            if (pos<0) titleCell.inner Text = titleText + "*";
            }
            </script>
            <style type="text/css">
            ..cellbottombor der { font-size:24pt }
            </style>
            </head>
            <body>
            <table>
            <tr>
            <td id="section5" height="37" align="center" class="cellbott omborder">
            System Data Maintainance
            </td>
            </tr>
            </table>
            <br>
            <input type="button" value="changedD etails()" onclick="change dDetails()">
            </body>
            </html>


            Comment

            Working...