/    Sign up×
Community /Pin to ProfileBookmark

javascipt validation for multiple select box

[FONT=”Arial”]Hi i am a fresher in php.I want to know the how javascipt validation is working for multiple select box. I search the site but don’t get he validation that passes multiple value to the database.
This is my php code [/FONT][FONT=”Arial Black”]echo “<select class=’studententer’ name=’course[]’ multiple=’multiple’ >”;
echo “<option value=’select’ selected>———select———-</option>”;

while($row=mysql_fetch_array($result))
{
$courseid=$row[‘SUBJECT_ID’];
$coursename=$row[‘SUBJECT_NAME’];
echo “<option value=’$courseid’ >$coursename</option>”;
}
echo “</select>”;
$sub–;[/FONT]

Thank you

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@bubakJun 26.2009 — To check to see if at least one element is selected in javascript you can do something like this:

[CODE]if (document.frm.elements[course[]'].selectedIndex == -1) {error += "Please select at least one course.n";}[/CODE]


If you would like to traverse a multiple element select, something like this would work:

[CODE]for (i=0; i<document.frm.elements[course[]'].length; i++) {
if (document.frm.elements[course[]'][i].selected) {do something....}
}[/CODE]


In both of these examples, it is assumed that the select box is inside of a form named frm.
Copy linkTweet thisAlerts:
@anoop07011986authorJun 30.2009 — Thank you bubak, i change the code exactly you said in the reply now the code is working.

Actually there are one more problem in my prvious code. I write the javascript focus function in the previous field to focus to the course field. actually that was also wrong.

The code was document.testform.course[].focus();

This was also a wrong statement

Thank you very much bubak
×

Success!

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