0
I need each of these checkbox options (if selected) to show the input field related to each of them. But when I select the checkbox it does not show the related text field that should be displayed.
Here’s the script I’m using
$('#quais_redes input[type="checkbox"]'). change(Function() { Let name = this.value; $('[data-label=' + name + ']'). css('display', this.checked ? '' : 'None'); }); <div class="form-group">
<label for ="quais_redes" id="quais_redes">Possui redes sociais?</label>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" id="rede_facebook" type="checkbox" name="redes[]" value="1">
Facebook
</div>
<div class="form-check">
<input class="form-check-input" id="rede_instagram" type="checkbox" name="redes[]" value="2">
Instagram
</div>
<div class="form-check">
<input class="form-check-input" id="rede_twitter" type="checkbox" name="redes[]" value="3">
Twitter
</div>
<div class="form-check">
<input class="form-check-input" id="rede_telegram" type="checkbox" name="redes[]" value="4">
Telegram
</div>
<div class="form-check">
<input class="form-check-input" id="rede_whatsapp" type="checkbox" name="redes[]" value="5">
Whatsapp
</div>
</div>
<div class="form-group" style="margin: 0 auto; display: none;">
<label for="instagram">Qual o seu Facebook?</label>
<input type="text" class="form-control" name="facebook" id="facebook" data-label="rede_facebook">
</div>
<div class="form-group" style="margin: 0 auto; display: none;">
<label for="instagram">Qual o seu Instagram?</label>
<input type="text" class="form-control" name="instagram" id="instagram" data-label="rede_instagram">
</div>
<div class="form-group" style="margin: 0 auto; display: none;">
<label for="twitter">Qual o seu Twitter?</label>
<input type="text" name="twitter" class="form-control" id="twitter" data-label="rede_twitter">
</div>
<div class="form-group" style="margin: 0 auto; display: none;">
<label for="twitter">Qual o seu Telegram?</label>
<input type="text" name="telegram" class="form-control" id="telegram" data-label="rede_telegram">
</div>
<div class="form-group" style="margin: 0 auto; display: none;">
<label for="twitter">Qual o seu Whatsapp?</label>
<input type="text" name="whatsapp" class="form-control" id="whatsapp" data-label="rede_whatsapp">
</div>
</div>
And how did you try to do with JS? You could post the code and describe the result obtained?
– Woss
Yes, of course! So, I ended up using this script, I tried to do a test with just one field to see if it worked but it didn’t. $(Document). ready(Function(){ $('#rede_facebook').on('input', Function(){ $('#facebook').prop('disabled', false); }); }); E put disable in the facebook field. Only the field is only disabled and not enabled. But in reality it was not to appear the field before gave select the checkbox, and it appears even without clicking the checkbox and is always disabled.
– Juliana Nascimento
It would be important to include in your question the CSS and the JS that you tried, so you can see that you are missing
– hugocsl
Yes, Hugo. But stopping to analyze, the Javascript code that I had put in it was not meant to hide but only to disable, you know? I need it to be hidden, not disabled. So anyway it was wrong the way I was doing but I’ll put here.
– Juliana Nascimento
Guys, I tried to solve using Ajax but it didn’t work either, I will edit the post by putting this way I did q ta more complete than the previous.
– Juliana Nascimento