disabling form elements help

Soldato
Joined
1 Feb 2006
Posts
8,188
hi, i am wanting to disable some form elements on a page i am writing but the drop down box i am using is generated using php and i cannot disable it using javascript no matter what way i try!

here is the php code:
Code:
echo '<select name="course" id="course_select">';
	$getCourseOptions = mysql_query("SELECT * FROM course_details");
	while($row = mysql_fetch_array($getCourseOptions))
	{
		$optionID = $row['course_id'];
		$optionName = $row['course_name'];
		echo "<option value='$optionID'>$optionName</option>";
  	}
	echo "</select><br /><br />";

On another form element I have this: (this comes directly before the php dropdown menu above)
Code:
			<select name="category" id="course_category" onchange="enable()">
				<option value="General">General</option>
				<option value="CourseSpecific">Course Specific</option>
			</select>

My enable javascript function is like this:
Code:
function enable() 
{
	disableElement = document.getElementById("course_select");
	disableElement.disabled=true;
}


Basically what I want to happen is that the course_select dropdown menu should only be enabled if the value of the course_category is set to CourseSpecific. I know the above code is kind of messy but its just something I was having a quick play around with.

Anyone know how I can get this to work?

Thanks in advance
 
What exactly doesn't work?

Does the getelementbyid return correctly?

Use message boxes to output values at different stages to help debug.
 
all the code seems fine but when i change the value in the course_category field the course_select field does not disable. Really can't work it out!
 
Back
Top Bottom