Besa
Besa

Reputation: 515

How to disable an input field for certain user?

I have an input field that I want to make it readonly for the users, and only the admin can change it .

<input value="http://google.com" class="form-control" readonly></div>

Upvotes: 0

Views: 370

Answers (2)

name me
name me

Reputation: 253

2 simple ways to do this. 1st you can incorporate javascript inside in your jsp. Then create function that would hide your the field that can be editted if the user is not admin.(Then show only the read-only or text field) Then show it otherwise which seemed a little complicated this way. But anyway, 2nd is you can use jsp standard tag library or jstl.. use . It works like a switch with case statements :) for reference please see: http://www.tutorialspoint.com/jsp/jstl_core_choose_tag.htm

Upvotes: 0

RudiDudi
RudiDudi

Reputation: 455

if you want do this as other said, you must have a database gestion, anyway the code that you must have is like:

<input id ="label1" value="http://google.com" class="form-control" readonly></div>
<script type="text/javascript">
  var isAdmin = "1" //this variable must be valorized with a flag or something that is supposed to be, for example 0 for users 1 for admins

  if(isAdmin==1){
    var checkVisible = document.getElementById("label1");
    checkVisible.readOnly= false;
  }
</script>

for sure it's not a professional solution but this can give to you and idea how it works

Upvotes: 1

Related Questions