简体   繁体   中英

Change ReadOnly Attribute of ASP.NET Web App using JQuery

Here is my HTML

    <td style="width: 4pt;">
</td>
<td>
    <span style="display: inline-block; color: Black; font-family: Arial; font-size: 9pt;
        font-weight: normal; width: 100pt; vertical-align: top;">Logic Ref Symbol</span>
</td>
<td>
    <input name="ctl00$MainContent$TabContainer1$TabPanel2$GeneralInformationControl$Reference Path"
        type="text" readonly="readonly" id="MainContent_TabContainer1_TabPanel2_GeneralInformationControl_Reference Path"
        class="textbox" groupname="Logical Symbol" style="font-family: Arial; font-size: 9pt;
        font-weight: normal; width: 150pt;" />
</td>
<td style="width: 4pt;">
</td>
<td style="width: 4pt;">
</td>
<td>
    <span style="display: inline-block; color: Black; font-family: Arial; font-size: 9pt;
        font-weight: normal; width: 100pt; vertical-align: top;">Logic Assignee</span>
</td>
<td>
    <select name="ctl00$MainContent$TabContainer1$TabPanel2$GeneralInformationControl$Logic Assignee"
        id="MainContent_TabContainer1_TabPanel2_GeneralInformationControl_Logic Assignee"
        class="dropdownlist" groupname="Logical Symbol" style="font-family: Arial; font-size: 9pt;
        font-weight: normal; width: 150pt;">
        </td>

When the Page loads initially, the Logic Ref Symbol is ReadOnly. When the Logic Needed dropdown is set to Yes, the ReadOnly property should disapper and user should be able to enter the information for that. I 've gone through numberous forums and tried different things but no luck in resetting the readonly property.

Infact one post says that We cannot set the readonly property to False ad it might be a security concern. However, I tried many of the approaches including

$('#'+logic_Type).prop('readonly', false);//Where Logic_Type contains my ID Name
var Logic_Type= $('[id$=' + logic_Type + ']').get(0).removeAttr('readonly');//This throws a Syntax error as unrecognized Expression

I tried with single and double quotes too. Nothing works, Am I missing anything? Does ASP.NET4.0 doesn't really support resetting the readonly property to false? I also tried document.getAttributebyId) Method and tr=ied to reset the proiperty but that returns null.

What am I missing here?

As your id contains a space, you need delimiters around the value:

$('[id="' + logic_Type + '"]').prop('readonly', false);

An alternative would of course be to not use a space in the id, then you can access it more easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM