Enable Field of a given table row via a button with JQuery

0

I am doubtful for this system in Jquery ,

The idea is to click EDITAR on a particular line to only activate the inputs of that particular line of edit clicked.

There are also two Edit Privilege, ADM e NORMAL , NORMAL should only edit the column NOME, o ADM the columns NOME e SALARIO this I got.

             Challenge                                     Adm         Normal

    <table border="1">
        <tr><td>Operações</td><td>Nome</td><td>Salário</td></tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit('editar')" value="Edit"><input class="excluir" type="button" onclick="excluir()" value="Excluir"></td>
            <td><input disabled  class="nome" type="text" name="nome"></td><td><input disabled class="salario"  type="text" name="salario"></td>
        </tr>



        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>

    </table>
</body>

<script type="text/javascript">
	
	var op = "";
	var privilegio = "";

	function acesso(op){
		privilegio = op;
	}


	function edit(){
		if(privilegio == 'adm'){
			$(this).parent().next().find('.salario').removeAttr('disabled');
			$(this).parent().next().find('.nome').removeAttr('disabled');
			
		}
		else{
			$('table').find('.nome').removeAttr('disabled');
		}
		
	}
</script>
    
asked by anonymous 13.03.2016 / 17:40

1 answer

0

below the problem resolution:              Challenge                                     Adm         Normal

    <table border="1">
        <tr>
            <td>Operações</td>
            <td>Nome</td>
            <td>Salário</td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td class="salario"><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td><td><input disabled  type="text" name="salario"></td>
        </tr>
        <tr>
            <td><input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir"></td>
            <td><input disabled type="text" name="nome"></td>
            <td><input disabled  type="text" name="salario"></td>
        </tr>
    </table>
</body>

<script type="text/javascript">
	
	var op = "";
	var privilegio = "";
	var excluindo = 0;

	function acesso(op){
		privilegio = op;
	}


	function edit(edit){
		if(privilegio == 'adm'){
			$(edit).parent().next().find('input').prop("disabled", false);
			$(edit).parent().next().next().find('input').prop("disabled", false);			
		}
		else{
			$(edit).parent().next().find('input').prop("disabled", false);	
		}

		$(edit).parent().html('<input type="button" onclick="confirmar(this)" value="Confirmar">');	
	}

	function confirmar(conf){
		if(excluindo == 1){
			excluindo = 0;
			$(conf).parent().next().find('input').val('');
			$(conf).parent().next().next().find('input').val('');
		}
		$(conf).parent().next().find('input').prop("disabled", true);
		$(conf).parent().next().next().find('input').prop("disabled", true);
		$(conf).parent().html('<input class="edit" type="button" onclick="edit(this)" value="Edit"><input class="excluir" type="button" onclick="excluir(this)" value="Excluir">');

	}

	function excluir(excluir){
		excluindo = 1;
		if(privilegio == 'adm'){
			$(excluir).parent().next().find('input').prop("disabled", false);
			$(excluir).parent().next().next().find('input').prop("disabled", false);			
		}
		else{
			$(excluir).parent().next().find('input').prop("disabled", false);	
		}
		$(excluir).parent().html('<input type="button" onclick="confirmar(this)" value="Confirmar">');	
	}
		

</script>
    
14.03.2016 / 00:49