basically, that
document.forms[0].word2.value
replaces
<input type="text" name="word2">
with whatever you assign it.
If I am assuming what you want is true, you could do something like:
function addWord(keyword) {
if (document.forms[0].word.value == "") {
document.forms[0].word.value = keyword;
} else {
if (document.forms[0].word2.value == "") {
document.forms[0].word2.value = keyword;
} else {
document.forms[0].word3.value = keyword;
}
}
}
You had a += in there before, which would have appended whatever was selected to the 2nd field. If the 2nd field had 'asdf' in it, you would have had 'asdfwhatever' rather than it setting the field with 'whatever' the conditions would have also broken if field2 had a value, and with the construct above, would set field 1 and field 3.
However, a better way to do this might be to keep track of a counter and increment after each is set -- otherwise when you add a 4th field, you're just going to get an unmanageable mess of nested ifs.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
|