-1
I’m starting with Javascript and have a little problem.
I have an HTML form where I have a field radio
where I have two options, Texto
and Página
. When I click on the option Texto
he carries a field input
to enter the title, when I select the Página
he shows me two fields one input
title and subtitle.
How would I do that logic?
<div class="form-group row">
<label for="title-type" class="col-sm-2 col-form-label">Tipo Título:</label>
<div class="col-sm-2">
<input name="title-type" type="radio" value="text" id="title-type" onclick="typeRadioButton()"> Texto
</div>
<div class="col-sm-2">
<input name="title-type" type="radio" value="page" id="title-type" onclick="typeRadioButton()"> Página
</div>
</div>
<div class="form-group row">
{{ Form::label('metadata', 'Título', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-sm-10">
{{ Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Digite um Titulo', 'required' => true]) }}
</div>
</div>
<div class="form-group row">
{{ Form::label('metadata', 'Sub-título', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-sm-10">
{{ Form::text('pagetitle', null, ['class' => 'form-control', 'placeholder' => 'Digite um Sub-Titulo', 'required' => true]) }}
</div>
</div>
<div class="form-group row">
{{ Form::label('metadata', 'Conteúdo', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-sm-10">
{{ Form::textarea('slot', null, ['class' => 'form-control', 'required' => true]) }}
</div>
</div>
<div class="form-group row">
{{ Form::label('metadata', 'Cor de fundo:', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-sm-10">
{{ Form::checkbox('Usar Padrão do site', '', false) }} Usar Padrão do site
<input type="color" name="background ">
</div>
</div>
<div class="form-group row">
{{ Form::label('metadata', 'Cor do título:', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-sm-10">
{{ Form::checkbox('Usar Padrão do site', '', false) }} Usar Padrão do site
<input type="color" name="color-title">
</div>
</div>
<div class="form-group row">
{{ Form::label('metadata', 'Cor do texto:', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-sm-10">
{{ Form::checkbox('Usar Padrão do site', '', false) }} Usar Padrão do site
<input type="color" name="color-text">
</div>
</div>
{{-- JQuert--}}
<script>
function typeRadioButton() {
var type = document.getElementsByName("title-type");
if (type[0].checked) {
alert('Text');
} else if (type[1].checked) {
alert('Page');
}
}
</script>
If you want a Javascript solution, you’d better post the rendered html in your question.
– Leandro Angelo
All right, there it is.
– Romulo Sousa