• 0
Sign in to follow this  
Guest Eduardo Assis

Checkbox / Input

Question

Guest Eduardo Assis

Tenho uma caixa de seleção e logo apos uma caixa de input,

Gostaria de: quando começar a escrever algo no Input esse checkbox perca a checagem e quando limpar o campo ele volte a ter um check

Abraços.

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
Guest Visitante

coloque no input

onkeypress='if(this.value == ""){document.getElementById("id_checkbox").checked == true;}else{document.getElementById("id_checkbox").checked == false'}

não testei mas deve funcionar

Share this post


Link to post
Share on other sites
  • 0
Guest Eduardo Assis

Não deu certo, estou mandando os 2:

<input type="checkbox" name=correspondencia checked id="correspondencia">

<input onkeypress='if(this.value == ""){document.getElementById("correspondencia").checked == true;}else{document.getElementById("correspondencia").checked == false}' name="enderecocorresp" type="text" id="enderecocorresp" size="40" maxlength='100' >

Abraços.

Share this post


Link to post
Share on other sites
  • 0

veja se é assim que você quer:

<script>
function Campo(texto)
{
if (texto != "")
	document.getElementById("correspondencia").checked = true;
else
	document.getElementById("correspondencia").checked = false;
}
</script>

<input type="checkbox" name=correspondencia id="correspondencia"> 
<input onkeyup="Campo(this.value);" name="enderecocorresp" type="text" id="enderecocorresp" size="40" maxlength='100'>
ou então mais simplificado:
<input type="checkbox" name=correspondencia id="correspondencia"> 
<input onkeyup='if(this.value != ""){document.getElementById("correspondencia").checked = true;}else{document.getElementById("correspondencia").checked = false;}' name="enderecocorresp" type="text" id="enderecocorresp" size="40" maxlength='100'>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this