mardi 24 mars 2015

How to show/hide dropdown when checkbox is selected

I need use JavaScript, but I'm new to it. I use php mostly. When checkbox is selected (to choose definite role in registration) - dependently of the role that you have chosen, to be shown or not 2 dropdowns. If you have chosen Student, I want not to be shown these 2 dropdowns - for school and class, if you have chosen teacher - to be shown.I'm using Codeigniter. That's my view:





<html>
<head>

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<?php
echo "<body>";
echo validation_errors();
echo "<div class='container'>";
echo form_open();

echo "<h3>Register</h3><br/>";
echo "<table border = '0' >";
echo "<tr><td> Username:* </td><td>";
$data=array(
'name' => 'username',
'class' => form_error('username') ? 'error' : ''
);
echo form_input($data);
echo "</td></tr>";
echo "<tr><td> Password:* </td><td>";
$data=array(
'name' => 'password',
'class' => form_error('password') ? 'error' : ''
);
echo form_password($data);
echo "</td></tr>";

echo "<tr><td> Choose role:* </td><td>";

echo form_checkbox('role_id[]', '1');
echo " Student ";
echo form_checkbox('role_id[]', '2');
echo " Teacher";
echo "</td></tr>";


echo "<tr><td> School:* </td><td>";
$options=array(
'pmg' => 'Harvard',
'eg' => 'Cambridge',
'class' => form_error('school[]') ? 'error' : ''
);
echo form_dropdown('school[]',$options);
echo "</td></tr>";
echo "<tr><td> Class:* </td><td>";
$options=array(
'8' => '8',
'9' => '9',
'class' => form_error('class[]') ? 'error' : ''
);
echo form_dropdown('class[]',$options);
echo "</td></tr>";

echo "</table><br/>";
$data=array(
'class' => 'btn btn-success ',
'value' => 'Register'
);
echo form_submit($data);
echo "</form>";
echo "</div>";
echo "</body>";
echo "</html>";






Aucun commentaire:

Enregistrer un commentaire