On 2006-10-03 10:41:12 +0200, "frankja" <fr************@gmail.comsaid:
I need to copy a lot of information to a lot of textfields from a text
file. It is possible to just put all the information on on long line
seperated by e.g. '*' and whenever a '*' occurs the tab-key is
automatically "pressed" so the cursor jumps to the next textfield?
Emulating a tab keypress seems a lot of trouble. You can use JavaScript
to split a string into substrings and copy each into a corresponding
form input, without using any UI trick.
Say your form inputs are all referenced in an array (use push() to add
each appropriate input element to the array so there won't be gaps in
the array indexes, that would make the rest of the code more
complicated than it needs to be).
function spreadStringIntoInputs(str, inputs)
{
var parts = str.split("*")
var s, i=0
if(parts.length inputs.length)
alert("uh oh, there aren't enough inputs to hold all the substrings.")
else
while(s=parts[i])
inputs[i].value=parts[i]
}
Now, that code is not very flexible. You should improve the way it
handles overflowing substrings (ignore them or dump them all into the
last input ?).
Either way, using some Array methods, you should be able to achieve
that by altering the 'parts' array and then proceed with the while()
loop, so you must remove the else statement: if(more strings than
inputs) make the array shorter somehow; whatever happened before, run
the loop.
--
David Junger