/    Sign up×
Community /Pin to ProfileBookmark

Limiting the size of a <select>

Is it possible to limit the size of a select box to, for example, 10 characters? The contents of my selects are gernerated from my database and some of the entries are a little long, forcing the select box to become v.wide – to wide for my template – and i’d like to keep them all to one size….is that possible??

I’ve tried adding size=”10″ with some odd results….

Cheers, Durbs

to post a comment
HTML

4 Comments(s)

Copy linkTweet thisAlerts:
@JoeCullenAug 09.2005 — Im not sure about limiting characters. But u can limit the width of the selection box (so the long text strings will just be hidden)

[code=html]
<select style="width:50px;">
<option selected>1</option>
<option>2</option>
<option>3</option>
</select>
[/code]


obviously change the width to a descent size for your site.
Copy linkTweet thisAlerts:
@Mr_JAug 09.2005 — You could possibly go

[code=php]
myOptions[i]=new Option(dataBasevalue[i])

if(myOptions[i].text.length>10){
myOptions[i].text=myOptions[i].text.substring(0,10)
}
[/code]


Or

[code=php]
if(dataBaseValue[i].length>10){
myOptions[i]=new Option(dataBasevalue[i].substring(0,10))
}
else{
myOptions[i]=new Option(dataBasevalue[i])
}
[/code]
Copy linkTweet thisAlerts:
@DurbsauthorAug 09.2005 — Cheers guys, in the end i've opted for reducing the font size as i realised cutting off the ends of some options would make them look identical. Even that is pushing it - i think, utimately, i'm gonna have to rework my template/layout to be more dynamic/accomadating width wise..... ?

Cheers anyhoo, Durbs
Copy linkTweet thisAlerts:
@bokehAug 09.2005 — If it is coming from a database you could use substr() to just display the first 15 or so lettrs of the string.
×

Success!

Help @Durbs 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.27,
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,
)...