ufancha ufancha - 6 months ago 9
PHP Question

how to validate a checkbox with multiple values

I have tried all i can to get a solution by googling, but couldnt get one.
i have the following php code which outputs a checkbox with multiple values, the values are from a database.

echo '<input type="checkbox" name="courses[]" value="'.$courses["id_course"].'" course-credit="'.$courses["course_credit"].'" onclick="return course_credit();"/> '.$courses["course_name"].';


when the check boxes are clicked, the javascript code inside course_credit() should run and adds up the course-credit values. i know how to go after that. but i am not sure how i can get the course-credit values.

Answer

This should work:

onclick="course_credit(this.value);"

In your function course_credit(), you'll get the value between the parenthesis. So do something like:

function course_credit(value){
// your code
alert(value);
}
Comments