I need help to disable select tag using JavaScript, this is my code :
<html> <head> <script type="text/javascript"> function disable() { if (window.document.form1.users.value == 0) { window.document.form1.test2.readOnly = true; window.document.form1.test.disabled = true; // this doesn't work } else window.document.form1.test2.readOnly = false; window.document.form1.test.disabled = false; } </script> </head> <body> <form name="form1"> <!--<select name="users" onchange="window.document.form1.nama_cabang.readOnly=false;">--> <select name="users" onchange="disable()"> <!--<select name="users" disabled="disabled">--> <option value="">Select a person:</option> <option value="1">Bob</option> </select> <br> <select name="test" disabled="disabled"> <option value="">Please select :</option> <option value="1">Yes</option> </select> <br> <input type="text" name="test2" readonly> </form> </body> </html>
In my algorithm :
- when user select "users" then "test2" and "test" would be rewritable.
- But when "users" change to default value should be "test2" and "test" wouldn't be rewritable / readonly.