How to use radio input with Hidden input

Asked

Viewed 670 times

-1

I want to record two fields of a table simultaneously, it would be the field "gale_fotos" and "gale_status" and I am using the code below, but it only records the field "gale_status" as No.

How do I have it recorded in the "gale_status" or SIM field when clicked on the YES option.

    <div align="center" style=" padding:2px; border-right:solid 1px;float:left; width:210px; height:auto; float:left;">
    <?php
    include '../conexao.php';
    $codigo = $_POST['codigo'];
    $gale_fotos = $_POST['gale_fotos'];
    $gale_status = $_POST['gale_status'];

    $query = mysql_query("SELECT * FROM menu");
    $res = mysql_fetch_array($query);

    if(isset($_POST['gale'])){

    $gale_fotos = $_POST['gale_fotos'];
    $gale_status = $_POST['gale_status'];
    $update = mysql_query("UPDATE menu SET gale_fotos = '$gale_fotos', gale_status = '$gale_status'");

    if($update == ''){
    echo "<script language='javascript'>
    window.alert('Erro ao Habilitar Link Galeria de Fotos!');
    </script>";
    }else{
    echo "<meta http-equiv='refresh' content='0; URL= menu_halitar_link.php'>
    <script language='javascript'>
    window.alert('Link Galeria de Fotos Habilitado com sucesso!');
    </script>";
    }}?>

    <form name="gale" action="" method="POST" enctype="multipart/form-data">
    <label>Habilitar o Link Galeria de Fotos?</label><br /><br />

    <label>Sim</label>
    <input type='radio' name='gale_fotos' value='<li><a href="<?php echo $res['dominio'];?>galeria.php" class="nav1">Galeria de Fotos</a></li><li class="divider"></li>' />
    <input type='hidden' name='gale_status' value='Sim' /><br />

    <label>Não</label>
    <input type="radio" name="gale_fotos" value="" />
    <input type="hidden" name="gale_status" value="Não" /><br />
    <input type="submit" name="gale" value="Atualizar" />
    </form>
    </div>

Thank you for your attention.

2 answers

0

With the event onclick javascript, assign a value (document.getElementById('campoOculto').value='valor') for the Hidden input (identified by a specific ID) according to the selected radio.

<label>Sim</label>
<input type='radio' name='gale_fotos' value='...'
onClick="document.getElementById('campoOculto').value='Sim'">
<label>Não</label>
<input type="radio" name="gale_fotos" value=''
onClick="document.getElementById('campoOculto').value='Não'"/>

<input id="campoOculto" type="hidden" name="gale_status" value="" />

-1

I did an implementation today for checkbox, but that also works for what you need with radio, take a look:

HTML:

<input id="chkCamp1" name="rad" type="radio" data-check="1" value="elemento 1"> elemento 1
<input id="chkCamp2" name="rad" type="radio" data-check="2" value="elemento 2"> elemento 2
<input type="text" data-view>
<input type="hidden" data-hide>

And Javascript:

$(function() {
    $('[data-check]').on('click', function() {
        var myInput = {valor: $(this).val(), id: $(this).data('check')};
        $('[data-view]').val(myInput.valor);
        $('[data-hide]').val(myInput.valor);
    });
});

It working: http://jsfiddle.net/ivanferrer/9wzsu3wt/5/

  • Ivan, first thank you so much for your attention to my problem. But I tried with your tip and it didn’t work, he keeps getting Status No when I select Yes. I managed to get him to get the correct status, but only by making two forms, one for each Input Radio and Idden, but he gets two buttons to update. I will keep trying, getting public the solution. But if anyone can give me a help I will be grateful.

  • if(isset($_POST['gale'])){&#xA;$gale_fotos = $_POST['gale_fotos'];&#xA;$update = mysql_query("UPDATE menu SET gale_fotos = $gale_fotos'")or die(mysql_error());&#xA;&#xA;if($gale_fotos != '<li><a href="<?php echo $res["dominio"];?>galeria.php" class="nav1">Galeria de Fotos</a></li><li class="divider"></li>'){&#xA; $update = mysql_query("UPDATE menu SET gale_status = 'Sim'");&#xA; }else{&#xA; $update = mysql_query("UPDATE menu SET gale_status = 'Não'") ;&#xA; } I made this change, but it only takes one of the options. Shouldn’t it compare and save according to this comparison? People, please... HEELPP.....

  • This is because the value returned from the gale_status field in PHP is always the second Hidden input of HTML. Try changing the values of the Hidden inputs and you will always return YES.

Browser other questions tagged

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