/    Sign up×
Community /Pin to ProfileBookmark

show message based on select box item chosen

I have a select box that the user can select 1-10. I want to show a special message if the user selects anything higher than 4 beside the select box. How would I go about doing this?

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@RobDavidMay 21.2007 — this should get you started

javascript

function validate(elem) {

var content = document.getElementById('content');

var value = elem.options[elem.selectedIndex].value;

if(value > 4){

content.innerHTML = "higher than 4";

}else{

content.innerHTML = "";

}

}


html

<select onChange="validate(this);">

<option value="0">Select an option</option>

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

<option value="6">6</option>

<option value="7">7</option>

<option value="8">8</option>

<option value="9">9</option>

<option value="10">10</option>

</select><span id='content'></span>
×

Success!

Help @jrthor2 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.17,
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,
)...