Clear field when selecting list

Asked

Viewed 44 times

1

I’m still new in this area of programming and I’m hitting myself to tweak a form.

I have a selection to do in a field, where if the user chooses mail, the email field "which is already filled" should be blank.

Code:

<fieldset id="dados_cadastro">
    <legend>Dados da Solicita&ccedil;&atilde;o de Forma de Envio de Boleto</legend>
    <div class="cadastro_line">
        <label style="width: 175px">Envio de Boleto:</label>
        <select name="boKa" id="">
            <option value=" "></option>
            <option value="1">Correio</option>
            <option value="" selected="selected"> Email</option>
            <option value="3"></option>
        </select>
    </div>
    <div class="cadastro_line">
        <label style="width: 175px">E-mail:</label>
        <input name="aaa" class="text" type="text" style="width: 175px" value="">
    </div>
</fieldset>

This is being programmed in advpl / HTML.

  • William, can you put in the code, maybe a print so we understand better.

  • In JS, you can delete the field content with this command : Document.getElementById('field'). value=''; // Clears the field

1 answer

1


Guy here has a simple example with JS, if the value you select in <option> of <select> for the value "mail" you clear the value of Email

let sel = document.querySelector('[name="boKa"]');

sel.addEventListener('change', limpa);

function limpa() {
    if (sel.value == 1) {
        let valor = document.querySelector('[name="aaa"]');
        valor.value = '';

        console.log('limpou o email');
    }
}
<fieldset id="dados_cadastro">
    <legend>Dados da Solicita&ccedil;&atilde;o de Forma de Envio de Boleto</legend>
    <div class="cadastro_line">
        <label style="width: 175px">Envio de Boleto:</label>
        <select name="boKa" id="">
            <option value=" "></option>
            <option value="1">Correio</option>
            <option value="" , selected="selected" , ''>Email</option>
            <option value="3"></option>

        </select>
    </div>
    <div class="cadastro_line">
        <label style="width: 175px">E-mail:</label>
        <input name="aaa" class="text" type="text" style="width: 175px" value="algo preenchido">
    </div>
</fieldset>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.