Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how to set the readonly attribute after clicking on href(button).

I want to set the readonly attribute to true...after clicking on the edit-href(button)....i have set the id for text field as "emp " in the form itself.....i had tried in the below manner...but it is not working.....

<script type="text/javascript">
$("#edito").click(function(){
  $("#emp").setAttribute("readonly", true);
});
</script>

<td>{{ (loop.index)+((page.current-1)*page.limit) }}</td>
<td>{{ employees.emplc.name|striptags|escape_css|escape_js|escape_attr }}</td>
<td>{{ employees.date_of_joining|striptags|escape_css|escape_js|escape_attr }}</td>
<td>{{ employees.u_group.name|striptags|escape_css|escape_js|escape_attr }}</td>
<td>{{ employees.u_group.role_id|striptags|escape_css|escape_js|escape_attr }}</td>
<td width="7%" >
  {{ link_to("employee/edit_emp_data/" ~employees.user_group,Edit', "class": "btn ", "id":"edito") }}
</td>


30.7k

Hi,

did you had a look at the javascript console debug message ? I think it should told you that

$ is not defined

you shouldn't put your javascript code in the view file because the view is build before the main layout (and then before jquery is loaded). So, put all your personnal javascript stuff in a seperate file and load that file in the main layout after jquery.

If you may also use assets manager wich is really powerfull: https://docs.phalconphp.com/en/latest/reference/assets.html

And finally, in your html code above, there is no element with id "emp"

i had done that to ....{{ javascript_include('custom/js/changeview.js') }} is included in index file where i had include all the other files too.



30.7k
Accepted
answer

OK, and what does the debuging console told you now ?

$("#emp").setAttribute("readonly", true);

what kind of html tag has id "emp" ? Because it is not there in the code you have given.