Topic: populating a select list (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=28574" title="Pages that link to Topic: populating a select list (Page 1 of 1)" rel="nofollow" >Topic: populating a select list <span class="small">(Page 1 of 1)</span>\

 
protoculture
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

IP logged posted posted 10-25-2006 18:16 Edit Quote

Hi there, I have the following code: ( which does not seem to work... any ideas ? ). I dont seem to get any errors, but yet the form remains unpopulated.

code tp add the item....

code:
document.data.location[location.length] = new Option(OptionText, OptionValue);




form item...

code:
<select id="dd_location2" name="location">
	<option value="0"></option>
	<option value="4" >Other Locations</option>
</select>



I've also tried this way as well, no dice.

code:
document.getElementById('dd_location2').length = new Option(OptionText, OptionValue);



(Edited by protoculture on 10-25-2006 18:30)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 10-25-2006 18:48 Edit Quote

Holy moly!!!



(Edited by poi on 10-25-2006 18:48)

protoculture
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

IP logged posted posted 10-25-2006 19:28 Edit Quote

Actually I had already done that and led me to the code you see before you.

the question still stands... can anyone see anything obvious in the code I might be missing?

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 10-25-2006 19:40 Edit Quote

Right.

... but the first code snippet in the first link returned by google works.

an even more generic search leeds straight to Peter-Paul Koch's excellent quirksmode.org

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

IP logged posted posted 10-26-2006 05:44 Edit Quote
quote:

protoculture said:

can anyone see anything obvious in the code I might be missing?


Aside from the fact that you are not specifying what to populate the list with?

Check the links posted....lots of good info in those top couple of results.

Of course, if you can be more specific as to *what* you want to automatically populate the list with, you might get more specific answers as well.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

IP logged posted posted 10-26-2006 16:54 Edit Quote

Um the first link on the google seach seems to return the same method he has

document.data.location[location.length] = new Option(OptionText, OptionValue);


That shoulds be

document.data.location[document.data.location.length] = new Option(OptionText, OptionValue);


Can't test right now but it seems it should actually be:

document.data.location.options[document.data.location.options.length] = new Option(OptionText, OptionValue);



.:[ Never resist a perfect moment ]:.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 10-26-2006 17:32 Edit Quote

Ok, ok the first link on my first google search is a bit incorrect :

I only read their ClearOptions() and AddToOptionList() functions and they are correct. It's how they use that is not. They pass the select itself instead of its options property. Tssss. But hey you can't expect 100% correct JS infos from a site called ASPWatch.

However the code on PPK's site is correct and it shows up in second place on my first search, and first place on my second search. Obviously someone didn't do his homework seriously.


Also, to make sure I'm really anal here, if you read out loud:

code:
document.getElementById('dd_location2').length = new Option(OptionText, OptionValue);

you can see it doesn't make sense. Length equal new option. No, that's not what you want. What you want is to add an option to the collection of options of a select.



ps: can anyone see it touches a nerve when I see that kind of threads ?



(Edited by poi on 10-26-2006 20:48)



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu