Jump to content
toarelli

Habilitar e Desabilitar Campo Input e Button

Recommended Posts

toarelli

Caros amigos.

Desculpa se postei minha dúvida em local errado, por favor me perdoa.

Preciso de um auxílio em JavaScript.

Como faço para quando clicar no button ALTERAR o input text seja ativado e depois que clicar em SALVAR o input text fica desativado.

Fiz um pequeno exemplo, com ajuda de alguns amigos, consigo esconder o button, mas preciso ativar e desativar o input.

o código:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Ativa e Desativa Button</title>
	
</head>
<body>
		<div class="page">
		
			<div class="formulario formCota">
				<div class="aviso red">
					Ativa e Desativa Button
				</div>
				<br/>
				<form>
					<label for="email">E-mail</label>
					    <input type="text" class="txtCota" name="email" />
						<br/>
					<label for="senha">Senha:</label>
					    <input type="password" class="txtCota" name="senha" />
						<br/><br/>
					
					<input type="submit" class="sb salvar hidden" name="salvar" value="salvar"/>
					<input type="submit" class="sb alterar" name="alterar" value="alterar"/>
					
				</form>
			</div>
		</div> 
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
	</body>
	
	<script type="text/javascript">
		$(function(){
		   $('.alterar').on('click', function(e){
		       e.preventDefault();
		       $('.alterar').addClass('hidden');
		       $('.salvar').removeClass('hidden');
		       return false;
		   });

		   $('.salvar').on('click', function(e){
		   		e.preventDefault();
		   		$('.alterar').removeClass('hidden');
		   		$('.salvar').addClass('hidden');
		   		return false;
		   });
		})
	</script>

	<style>
		.hidden{
			visibility: hidden;
		}
	</style>
	
</html>

Grato,

Toarelli

Share this post


Link to post
Share on other sites
coxosclassic

Boas,

Existe a propriedade "disabled" para inputs.

Usa a mesma lógica que tens para mostrar/esconder os botões, para ativar/desativar o input de texto.

Algo tipo:

document.getElementById("o-teu-input").disabled = true/false

cumps,


Cumps,

cc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.