insertCell problems

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

    insertCell problems

    Trying to modify some code from :

    But having some problems. Cant work out how/why its not adding rows in
    the right place. seems strange to me. Im trying to get the NS code
    working first since that appears to be a bit harder to figure out..
    heres my code..


    I was guessing it was something to do with var f but playing around
    with that seems to make things worse.

    Any help much appreciated. I have a might headache and now need some
    chocolate to compensate. :)
  • DU

    #2
    Re: insertCell problems

    will wrote:[color=blue]
    > Trying to modify some code from :
    > http://www.faqts.com/knowledge_base/view.phtml/aid/2357
    > But having some problems. Cant work out how/why its not adding rows in
    > the right place. seems strange to me. Im trying to get the NS code
    > working first since that appears to be a bit harder to figure out..
    > heres my code..
    > http://www.sourceymonkey.com/tmp/upload.html
    >
    > I was guessing it was something to do with var f but playing around
    > with that seems to make things worse.
    >
    > Any help much appreciated. I have a might headache and now need some
    > chocolate to compensate. :)[/color]

    I have not tested the code but I am able to make the following
    comments/recommendations :

    1- You can remove language="Javas cript1.1" since language is deprecated
    and has been superseded by type

    2- var row = table.insertRow (++f);
    Here the new f value is incremented and is now, say, 1 (was 0 before the
    incrementation) .
    var row2 = table.insertRow (f+2);

    It looks like you're giving the instruction to insert a row at index 3.
    Is that intended?
    When I try your file, the Image Caption numbers as output by
    input.value = 'Image Caption'+f;
    do not follow accordingly,.. so this is most likely the source of your
    logical bug in your script.

    3- input.setAttrib ute('type', 'file');
    "General rule: don't use setAttribute() when a better way of setting the
    attribute is available"

    HTMLInputElemen t.type
    type of type DOMString, modified in DOM Level 2
    The type of control created (all lower case).


    So,
    input.type = "file";
    input.type = "text";
    and
    input.type = "button";
    seem more appropriate

    4- input.size = '24';
    size of type unsigned long, modified in DOM Level 2

    So
    input.size = 24;
    seems more appropriate

    5- Regarding browser support detection, the script has logical problems
    and could be more precise. MSIE 5.x and MSIE 6 will execute the
    cell.innerHTML = ...; instruction when it should be only for MSIE 4.

    DU
    --
    Javascript and Browser bugs:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


    Comment

    • will

      #3
      Re: insertCell problems

      Thanks for all that DU. Its been a while since Ive had to delve into
      Javascript so the help is appreciated.

      DU <drunclear@hotR EMOVEmail.com> wrote in message news:<bhgpn5$iq l$1@news.eusc.i nter.net>...[color=blue]
      > 2- var row = table.insertRow (++f);
      > Here the new f value is incremented and is now, say, 1 (was 0 before the
      > incrementation) .
      > var row2 = table.insertRow (f+2);
      >
      > It looks like you're giving the instruction to insert a row at index 3.
      > Is that intended?
      > When I try your file, the Image Caption numbers as output by
      > input.value = 'Image Caption'+f;
      > do not follow accordingly,.. so this is most likely the source of your
      > logical bug in your script.
      >[/color]

      Yeah I thought this may be my problem. How do I plus one without
      plusing one? if you see what I mean. Just temporarily.. so kind of
      like:
      var n = f (+1);
      so f stays the same and the resulting number is used.

      Cheers

      W

      Comment

      • DU

        #4
        Re: insertCell problems

        will wrote:
        [color=blue]
        > Thanks for all that DU. Its been a while since Ive had to delve into
        > Javascript so the help is appreciated.
        >
        > DU <drunclear@hotR EMOVEmail.com> wrote in message news:<bhgpn5$iq l$1@news.eusc.i nter.net>...
        >[color=green]
        >>2- var row = table.insertRow (++f);
        >>Here the new f value is incremented and is now, say, 1 (was 0 before the
        >>incrementatio n).
        >> var row2 = table.insertRow (f+2);
        >>
        >>It looks like you're giving the instruction to insert a row at index 3.
        >>Is that intended?
        >>When I try your file, the Image Caption numbers as output by
        >>input.value = 'Image Caption'+f;
        >>do not follow accordingly,.. so this is most likely the source of your
        >>logical bug in your script.
        >>[/color]
        >
        >
        > Yeah I thought this may be my problem. How do I plus one without
        > plusing one? if you see what I mean. Just temporarily.. so kind of
        > like:
        > var n = f (+1);
        > so f stays the same and the resulting number is used.
        >
        > Cheers
        >
        > W[/color]


        Avoid adding more variables and code into your script. First try to
        understand the logical bug in your script. Your problem has nothing to
        do with an insertCell difficulty. So do not add more variables.

        init() is called twice: as the document loads and as the user clicks the
        button: that's a logical bug here.

        If "f" is going to be a row iterator, then use it as a global variable
        and don't query the table.rows.leng th at all. So, IMO, the init()
        function is useless, not necessary, just makes the code more complex.

        When facing logical bugs, you should try to simplify your
        program/functions/scripts, not make it more complex.
        Use Venkman javascript debugger to monitor watches and local variable
        values, otherwise use alert to output values.
        So, here, you can safely delete
        document.formDi splay.nnum.valu e = n;
        document.formDi splay.fnum.valu e = f;
        and its related html code.

        If "f" is going to be a very important variable in your code, then give
        it a meaningful, intuitive, self-explanatory identifier. Others
        reviewing your code, helping out, or yourself in 3 months from now will
        save time trying to figure out the script. I assure you that such simple
        basic and sane coding practices save a lot of time and frustrations in
        the long run. Tutorials, Netscape DevEdge, MSDN columns all say the same
        on this issue and on debugging.

        Always make sure your whole html markup is valid and validated in the
        first place; use a full doctype declaration. You make your page
        compliant, interoperable and you avoid problems of all kinds later. You
        eliminate possible sources of differential rendering when you write/test
        your script functions.

        var input = document.create Element('INPUT' );
        input.setAttrib ute('type', 'file');
        input.name = 'imageup' + f;
        input.onchange = function () { addInput(); };

        This above code will create another line when just choosing a file,
        while the other code will do the same if clicking the "Select another
        file" button: so, you have here a logical bug, a duplication. The
        input.onchange = function () { addInput(); };
        should be removed entirely.

        Drop entirely the setAttribute call in your code: you don't need that
        and there is a much better, more reliable way to assign a type to a
        input DOM node:
        input.setAttrib ute('type', 'file');
        should be
        input.type = "file";

        I think you can safely drop the entire block testing document.all as I
        would be very much surprised if MSIE 4 can embed new additional and
        functioning form elements into a form. Since MSIE 5+ supports DOM-1
        methods, then you can safely drop the whole block of
        if(document.all ). Anyway, you should first try to support MSIE 6, NS
        7.x, Opera 7.x

        action="whateve r" is not valid; action="" is ok though.

        You should not try to remove the "old" buttons for usability reasons.
        The user might want to change his mind.

        I did your valid webpage and it works perfectly, impeccably, flawlessly
        on Opera 7.11, MSIE 6 for Windows and Mozilla 1.4 and I think it has a
        better design than in your original page (it has only 1 "Select another
        file" button). I will upload it later.

        DU
        --
        Javascript and Browser bugs:

        - Resources, help and tips for Netscape 7.x users and Composer
        - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


        Comment

        • DU

          #5
          Re: insertCell problems

          DU wrote:
          [color=blue]
          > will wrote:
          >[color=green]
          >> Thanks for all that DU. Its been a while since Ive had to delve into
          >> Javascript so the help is appreciated.
          >>[/color][/color]

          [snipped]
          [color=blue]
          >
          > I did your valid webpage and it works perfectly, impeccably, flawlessly
          > on Opera 7.11, MSIE 6 for Windows and Mozilla 1.4 and I think it has a
          > better design than in your original page (it has only 1 "Select another
          > file" button). I will upload it later.
          >[/color]

          Sorry. Kinda forgot about it. Here it is:




          DU
          --
          Javascript and Browser bugs:

          - Resources, help and tips for Netscape 7.x users and Composer
          - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


          Comment

          Working...