Jacob Chong Jacob Chong - 6 months ago 3
Javascript Question

Conditionally set editable or readonly text field

How to conditionally enable or disable to editable field (edit/read only)? I used session role from database to make condition on the text field. However, I don't know how to proceed it...


<tr class="row1">
<td width="30%"><div align="left">Customer name1</div></td>
<td width="100%">
<div align="left">
<input type="text" name="CMCNA1" id="CMCNA1" style="width:100%;" pattern="[A-Za-z]+" title="Please insert alphabetical only" maxlength="35"/>


@Narayan, This is what i did, n functioning... However i am not sure whether what i did on the radio button disable is true method, because radio button unable to set readonly.

function makerCheckerField()
    var role= "<?php echo $_SESSION['login_user_role']; ?>";
    var maker="Checker";
        if (role == maker){   
            var x, l=fields.length;
            var fieldname;
                for(x=0; x<l; x++){
                    document.getElementById(fieldname).setAttribute("readonly", true);
            var radios0 = document.form0.CSCCAT;
                for (var i=0, iLen=radios0.length; i<iLen; i++) {
                radios0[i].disabled = true;
            var radios1 = document.form0.CAANSF;
                for (var i=0, iLen=radios1.length; i<iLen; i++) {
                radios1[i].disabled = true;
        } else {}