www.webdeveloper.com
Results 1 to 5 of 5

Thread: My own object more than once

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    My own object more than once

    Hi,
    Complitely new to java script (I have some coding experience nevertheless), I am trying to implemente a spin button. I found some code to create it there:
    http://code.google.com/p/prototype-spin-button/
    When I have only one occurence of it, it's working fine. But what I have is a loop that create 10 instencies of it. Here is what's in the loop:
    </td>
    <td><input type="text" size="3" class="spin-button" id="spinbutton" style="width:6ex" <?php echo "name= 'coef'.$i" ?>/>
    <script type="text/javascript">
    new SpinButton($('spinbutton'),{min:0, max:3, step:0.1, reset:1.6});spinnbr=sinnbr+1;
    </script>
    </td>

    and I get my 10 spin buttons. But only the first one is accessible, and it doesn't work well, say if you click the up button, it will increase by 10 steps(actually by the number of object created x the step value.)
    Thanks for help.
    Thierry

  2. #2
    Join Date
    Feb 2008
    Posts
    1,666
    You'd need 10 HTML elements, numbered as shown below, then you can use script such as the following:
    Code:
    <script type="text/javascript">
    for(var x=1; x<=10; ++x)
    {
      new SpinButton($('spinbutton'+x),{min:0, max:3, step:0.1, reset:1.6});
    }
    </script>

  3. #3
    Join Date
    Jan 2009
    Posts
    3
    Thank you, but as soon as I change $('spinbutton'), say to $('spinbuttona') in the expression:
    new SpinButton($('spinbutton'),{min:0, max:3, step:0.1});
    the spin button become non-responsive, even if I have only one button on the form.
    Thierry

  4. #4
    Join Date
    Feb 2008
    Posts
    1,666
    Is there an
    Code:
    id="spinbuttona"
    in your page?

  5. #5
    Join Date
    Jan 2009
    Posts
    3
    Thank you, that did it!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles