Reputation: 1
So i am Working on a project and here i have a dropdown in which i have certain values which change their color on certain changes.
Like the available values a colored as green and unavailable values are colored as red
So if i want to validate options in a dropdown, and the user should be stopped from selecting the red values i.e. he won't be able to submit that value, what should be done
Here is the code sample of my project.
Controller:
public function get_teacher()
{
$room=$this->input->post('room_id');
$date=$this->input->post('exam_date');
$exam=$this->input->post('exam_id');
$response=$this->alo->get_teacher($date,$exam,$room);
echo $response;
}
Model:
function get_teacher($date,$exam,$room)
{
//$res .= "<option style='color:red'
value='".$teacher['teacher_id']."'>".$teacher['teacher_name']."</option>";
//such options are given
}
Now on submit i want the user not to submit this red color option
How to validate in javascript or any other method in codeigniter model conditions that could help.
Upvotes: 0
Views: 64
Reputation: 1185
Use the html attribute disabled and you will not need to use javascript.
https://www.w3schools.com/tags/att_option_disabled.asp
However you should also validate in php after submission that the value is valid because people can manipulate any form data before/during submission regardless of "disabled" or any javascript validation.
Upvotes: 1