By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,461 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,461 IT Pros & Developers. It's quick & easy.

JScript passing value

P: n/a
IS
Hi folks,

Any ideas why this doesn't work?

<SCRIPT LANGUAGE="JavaScript">
<!--
f = document.forms[1];
e = f.elements;
str = new String(e[0].value);
len = document.forms['testform'].d.options.length;
document.forms['testform'].d.options[len] = new Option(str, '1');
</script>

Basicaly, I am trying to fill my combo box on a HTML page (SELECT OPTION
field) manually, but the vallue I get every time is 'null', i.e. empty
string.
*Suspected error in the red line, since if I put in the last line "....new
Option('some','1');" it works.

I must have made some ridiculous error I can't see, so plz be free to make
fun of me :))

Thanks in advance.
IS
btw. if I put up an event at the Text field (onChange) the values can be transfered to my combo box trought a function call, but are lost as soon as I press Submit button I have next to my Text field.
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <bp**********@shiva.neobee.net>, fi*******@yahoo.com
enlightened us with...
Hi folks,

Any ideas why this doesn't work?
You only have one form on the page?

<SCRIPT LANGUAGE="JavaScript">
<script type="text/javascript">
<!--
f = document.forms[1];
This gets the second form. I hope that was what you wanted.
Otherwise, forms[0].
e = f.elements;
str = new String(e[0].value); I hope this element has a value and is either a text input or text area.
You didn't check.
len = document.forms['testform'].d.options.length; I hope the select is named d.
document.forms['testform'].d.options[len] = new Option(str, '1');
</script>

Basicaly, I am trying to fill my combo box on a HTML page (SELECT OPTION
field) manually, but the vallue I get every time is 'null', i.e. empty
string.
*Suspected error in the red line, since if I put in the last line "....new
Option('some','1');" it works.
No "Red lines" for people with plain text mail readers.


You maybe better off using names, not numbers. Otherwise, if you move
elements around, you have to change all the code! I suspect the problem
is with e[0].value.
Try e["elementname"].value

Oh, and submitting "loses" values - the form blanks out once the page
location changes.

--
--
~kaeli~
In democracy your vote counts. In feudalism your count votes.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.