Radio button flag

Asked

Viewed 72 times

0

Good afternoon, I have a mobile application written in Mobileui and JS, where I have an Alert for the company exchange function. In this Alert has radio inputs, which is to select only one of the options. I wish when opening Alert it always came with the selected input marked, but it always brings me blank.

Could you help me? Follow below code.

inserir a descrição da imagem aqui

Javascript file

var empresaSelect

function trocarEmpresa(){
    map.setClickable(false)
    alert({
        id: 'alertEmpresa',
        title: 'Trocar Empresa',
        message: 'Realize a troca de empresa!',
        template: 'empresaVendedor',
        width: '60%',
        buttons:[
            {
                label: 'OK',
                onclick: function() {
                    closeAlert('alertEmpresa')
                    map.setClickable(true)
                    findFormVendedor()
                    myLocation()
                }
            },
            {
                label: 'Cancelar',
                onclick: function() {
                    closeAlert('alertEmpresa')
                    map.setClickable(true)
                }
            }
        ]
    })
}

function selectedEmpresa(index) {

    empresaSelect = empresas.filter(function (e, i) {
        return i == index ? e : null
    })

    empresaSelect = empresaSelect[0]
}

document.addEventListener('backPage', function() {
    closeAlert('alertEmpresa')
})

HTML file

<div class="hidden" id="empresaVendedor">
        <div class="list">
            <div class="item" data="empresas">
                <h2>${razaoSocial}</h2>
                <div class="right">
                    <input name="radio-emp" type="radio" class="teal" onclick="selectedEmpresa($$index)">
                </div>
            </div>
        </div>
    </div>
  • 2

    Have you tried setting the input state to checked straight into the html tag? Like this: <input checked name="radio-emp" type="radio" class="teal" onclick="selectedEmpresa($$index)"> ?

1 answer

0

Well it is something easy to solve, use the "Checked" property of the input (HTML) In your code:

    <div class="hidden" id="empresaVendedor">
        <div class="list">
            <div class="item" data="empresas">
                <h2>${razaoSocial}</h2>
                <div class="right">
                    <input name="radio-emp" type="radio" class="teal" onclick="selectedEmpresa($$index)" checked >
                </div>
            </div>
        </div>
    </div>

Reference: https://www.w3schools.com/tags/att_input_checked.asp

Browser other questions tagged

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