0

Hello guys I just want to ask how can i change html attribute values using an event in jquery. For example I have a user list filled with information and there is a button update and cancel. The user information is READONLY but when the user click the button update it will remove the READONLY attribute in my textboxes.

Here's my simple code:

  <div style="display: none" id="form_edit" class="k-content">
        <table border="0">

            <tr>
                <td>
                    &nbsp;&nbsp;&nbsp;<label>P.O. #</label>
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;<input type="text" name="po" value="<?php echo $order_code; ?>" readonly="readonly" />
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;<label>SUPPLIER NAME</label>
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;<input type="text" name="suppliername" value="<?php echo $sname; ?>" readonly="readonly"" />
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;<label>Contact Person</label>
                </td>
                 <td>
                    &nbsp;&nbsp;&nbsp;<input type="text" name="person" value="<?php echo $contactperson; ?>" readonly="readonly" />
                </td>
            </tr>

            <tr>
                <td>
                    &nbsp;&nbsp;&nbsp;<label>TIN #</label>
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;<input type="text" name="tin" value="<?php echo $tin; ?>" readonly="readonly" />
                </td>
            </tr>

            <tr>
                <td colspan="6" style="text-align: right">

                    <input type="button" value="UPDATE" class="k-button" id="submit_form"/>
                    <input type="button" value="HIDE" class="k-button" id="close_form"/>
                </td>
            </tr>


        </table>
    </div>

My jquery

  $("a[name=edit_order]").click(function (e) {
        $("#window_edit").data("kendoWindow").open();
        e.preventDefault();
    });

    $("a[name=remove_order]").click(function (e) {
        $("#window_remove").data("kendoWindow").open();
        e.preventDefault();
    });

    /*here's the part that will remove the readonly attribute but how can i do that?
    $("#update_supplier").click(function(){
        $("#form_edit").show({
            effect: "blind",
            animation: 1000
        });

        $("#update_supplier").hide({
            effect: "fade",
            animation: 1000,
        });
    });

    /*if close bring back again the readonly*/
    $("#close_form").click(function(){
        $("#form_edit").hide({
            effect: "blind",
            animation: 1000
        });

         $("#update_supplier").show({
            effect: "fade",
            animation: 1000,
        });
    });
3
  • When you click on update button right you want remove readonly from textbox , but its also submit form when you click on update button. Commented Aug 27, 2013 at 7:44
  • Ok sorry my fault I will change it to button Commented Aug 27, 2013 at 7:49
  • Check my edit i m sure it will help you to solve your issues Commented Aug 27, 2013 at 7:49

2 Answers 2

4

Try this code :

$('#submit_form').on('click', function () {
    $('input[name="suppliername"]').removeAttr('readonly');
});

Check my edit.

Sign up to request clarification or add additional context in comments.

2 Comments

It works. But what if if im going back again to readonly how's that?
@RochelleCanale means ?
4

Try this

$('#submit_form').on('click', function () {
    $('input["readonly"]').removeAttr('readonly');
});

5 Comments

Where you find class .suppliername ?
i can't see any class with this name ?
Sorry guys my Update button is also a submit button I changed it to button
@Anton i didn't downvote infact i have also downvote ? so explain why down vote ?
@DevangRathod I didn't downvote either... both our answers are correct i infact upvoted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.