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">
  $("#emp").setAttribute("readonly", true);

<td>{{ (loop.index)+((page.current-1)*page.limit) }}</td>
<td>{{|striptags|escape_css|escape_js|escape_attr }}</td>
<td>{{ employees.date_of_joining|striptags|escape_css|escape_js|escape_attr }}</td>
<td>{{|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") }}



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:

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.


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.