/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] list box with discription

hi. i stumbled across this javascript snippet that allows a user to select an option from a drop down list box and when they select something, it will put a description in a textbox. this script has worked wonders for small things, but when i went to use it for a larger drop down list with about 250 items, it all of a sudden will not work. is there something that needs to be changed? Thanks!

[code]
<select name=”chargenumber” class=”dropdown” onChange=”changecontent(this)” size=”5″>
<option value=”1″>something</option>
<option value=”2″>somethig else</option>
<option>etc.</option>
</select>

<textarea rows=”6″ name=”phrase” cols=”100″ wrap=”virtual” class=”textarea”></textarea>

<script language=”JavaScript”>

var thecontents=new Array()

thecontents[1]=”some text goes here”
thecontents[2]=”some more text goes here”
thecontents[3]=”etc.”

function changecontent(which){
document.addcharge.phrase.value=thecontents[which.selectedIndex]
}

document.addcharge.phrase.value=thecontents[document.addcharge.selectbox.selectedIndex]
</script>[/code]

except in my case, i have about 250 entries in the array. What exactly is wrong? thanks for your help!

oh yeah, i keep getting an error saying that that “changecontent” is not defined. but i only get this error on the big list. thanks for any help!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisAug 24.2006 — It is probably a typo. Check for unterminated strings in your 250 entries, especially if you have embedded quotes.
Copy linkTweet thisAlerts:
@bla4freeauthorAug 24.2006 — ...especially if you have embedded quotes.[/QUOTE]
now that you mention it, some of the entries have things like 3" (3 inches). would input like that be causing the problem?
Copy linkTweet thisAlerts:
@bla4freeauthorAug 24.2006 — alright, i went added a Replace function to my array generation and replaced all single and double quotes with:
' and "

i'm still getting the error though.

it won't let me put the symbols for single and double quotes but i have replaced them though. any ideas?
Copy linkTweet thisAlerts:
@gil_davisAug 24.2006 — You can either use single quotes to enclose strings so that a double quote is seen as a literal, or you can embed the "& string" for double quote (&quot?, or you can spell it out (in.).
Copy linkTweet thisAlerts:
@bla4freeauthorAug 24.2006 — after looking at the list, i noticed 2 of the array entries were on multiple lines instead of just one. but all the information was being pulled from a database so I had to play with it before it worked. Thanks very much for your help!

Jeff
×

Success!

Help @bla4free spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...