How to concatenate RadioButtons values in Razor / HTML?

0

I have a question and it's kind of hard to find a practical way to solve it.

I created a groupbox with 10 radiobuttons . I would like to know the best practice so that when the user marks one of them I store this value in a variable so that I can concatenate those values with 2 more groups.

Example:

RadioButton1 of groupbox1 is 1, RadioButton of groupbox2 is 2.

It should pick up the numbers and put one in each variable so that I can concatenate side by side resulting in (12) and not (3), and after that do a power calculation using the 3rd groupbox value. p>     

asked by anonymous 03.04.2014 / 00:41

1 answer

2

As the @give spoke the solution to this problem might be better in Javascript.

Follow example using HTML + Javascript with JQuery and JSFIDDLE working

HTML:

<form>
    <fieldset>
        <legend>Grupo 1 (Primeiro Dígito):</legend>
        <input type="radio" name="grupo1" value="1"/> 1<br/>
        <input type="radio" name="grupo1" value="2"/> 2<br/>
        <input type="radio" name="grupo1" value="3"/> 3<br/>
    </fieldset>
    <fieldset>
        <legend>Grupo 2 (Segundo dígito):</legend>
        <input type="radio" name="grupo2" value="1"/> 1<br/>
        <input type="radio" name="grupo2" value="2"/> 2<br/>
        <input type="radio" name="grupo2" value="3"/> 3<br/>
    </fieldset>
    <fieldset>
        <legend>Grupo 3 (Potencia):</legend>
        <input type="radio" name="grupo3" value="1"/> 2<br/>
        <input type="radio" name="grupo3" value="2"/> 3<br/>
        <input type="radio" name="grupo3" value="3"/> 3<br/>
    </fieldset>
    Resultado:
    <input type="text" id="txtResultado"/>
</form>

Javascript:

$(document).ready(function(){
    $('input:radio').on('click',CalculaResultado);
});

function CalculaResultado(oRadio){
    var grupo1 = $('input:radio[name="grupo1"]:checked').val();
    var grupo2 = $('input:radio[name="grupo2"]:checked').val();
    var grupo3 = $('input:radio[name="grupo3"]:checked').val();
    var resultado = parseInt(grupo1.toString() + grupo2.toString()) 
    resultado = Math.pow(resultado,parseInt(grupo3))
    if (!isNaN(resultado))
        $('#txtResultado').val(resultado);
    else 
        $('#txtResultado').val(0);
}
    
03.04.2014 / 14:32