set input field to readonly using jQuery

ถามตอบ ปัญหาการพัฒนา Extension ไม่ว่าจะเป็น Module plugin Component หรือ แม้แต่ template การปรับแต่งโค้ด Joomla ต่างๆ ทุกเวอร์ชั่น 1.5 2.5 หรือ 3.x

Moderators: mindphp, ผู้ดูแลกระดาน

coquilla18
PHP VIP Members
PHP VIP Members
Posts: 1088
Joined: 20/01/2014 11:27 am

set input field to readonly using jQuery

Postby coquilla18 » 28/07/2014 12:15 pm

on XML form,
we can set field to readonly buy using readonly="true"

but we can also use jQuery to set it to readonly
on views folder, open the layout file or the default.php file under the tmpl folder.
com_example/sample/tmpl/default.php

in order to set specific field to readonly
insert this code on your script above the table

Code: Select all

<script>
jQuery(document).ready(function() {
                jQuery('#field_id').attr('readonly',true);
});
</script>

The code above will the field that has the same field_id which you call on your jQuery


if you want to set more field to readonly easier, create the same class name of every field you want to set.. and on your script, code this below

Code: Select all

<script>
jQuery(document).ready(function() {
                jQuery('table').find('input.classname').attr('readonly',true);
});
</script>

the code above will find all field that has class="classname" and it will be set to readonly

Return to “Joomla Development”

Who is online

Users browsing this forum: No registered users and 6 guests