Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [SOLVED] Distribute numbers into a form

    The solution for my problem below is to place the distribute button inside the form. Now the code seems to work just fine.

    ----------------

    I have a code here that used to distribute a list of numbers into the appropriate boxes in a form. Now, it is not working and I am not sure why. I recently moved some HTML code around, but I can't imagine that I changed anything major.

    Pasting a set of numbers, 1, 2, 3, 4, each separated by a carriage return, should put them into the first four form boxes. Each consecutive box in the form, where the values will be placed, is labeled output0, output1, output2 and so on.

    This is the javascript, which is in the <head> section of the page:

    Code:
    <!--
    window.onload = function(){
      var myButton = document.getElementById('foo');
      var myForm = document.getElementById('ratings');
      myButton.onclick = function(evt){
        // 'myForm' is the form element itself
        var ssInput = myForm.elements.ssPastebox;
        var newrating = ssInput.value.split("\n");
        for (var i=0,len=newrating.length;i<len;++i){
          var output = myForm.elements["output"+i];
          if (output) output.value = newrating[i];
        }
        return false;
      };
    }
    // -->
    The relevant HTML code is here:

    Code:
    <p class="descript">
    <button id="foo">Distribute Ratings</button>
    <input type="reset" value="Reset Form">
    <input type="button" value="Clear All Fields" onclick="javascript:clearForms()"></p>
    </p><br />
    
    <p class="descript">-------------------</p><br />
    
    <form name="rate_form" id="ratings" method="post" action="ratescan.php">
    
    <table class="rate">
    <tr>
    <td class="rate_imbed">
    <table class="rate_imbed">
        <tr>
            <td class="ratedept"><b>HEADER</b>
        </tr>
        <tr>
            <td class="ratedeptshade"><a href="dept.php">Department: </a></td>
            <td class="ratenumshade" style="bgcolor: gray"><input class="rate" type="text" name="output0"  value=""></td>
        </tr>
    Any insight at all would be appreciated. Even a simpler way to distribute the values would be helpful. Thanks.
    Last edited by bovis; 08-22-2010 at 10:57 PM. Reason: SOLVED


 

Posting Permissions

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