...

View Full Version : [SOLVED] Distribute numbers into a form



bovis
08-22-2010, 11:45 PM
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:


<!--
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:


<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum