Change radio button properties from select on select

0

Dear, I see myself in the following situation where I can not imagine a solution:

We have a selection field in html containing some Brazilian states and the Federal District, when choosing an option, this would lead me to open another type of choice a radio button, between Capital and Interior being each capital and the option of interior with their respective values, where I would take this value of the given capital or the interior and would take to make an account multiplying a value of another radio button equivalent the daily ones to there then to show that value in a text field.

Exemplo Numero de diárias: ()Uma diária (x)Duas diárias ()Três diárias Selecione o estado: Select SP\/ //Apareceria outro radio button: (x)São Paulo () Interior In the case of São Paulo, the value would be R $ 200.00 per day then the textfield with the javascript help would be: Value = 400.00

            <select name="estado" id="estado" >
            <option name="nenhum" value=""> Escolher </option>
            <option name="DF" value="DF"> Distrito Federal </option>
            <option name="SP" value="SP"> São Paulo </option>
            <option name="outros" value="Outros"> Outros Estados 
</option>

// Open multiple choice of two options if the user chose the Federal District, then

<input required="required" value="Brasília" name="capital" type="radio">  
<label for="capital">Brasília</label> <input required="required"  value="Interior" name="capital" type="radio"><label         for="capital">Interior</label>

// Note that depending on the select field the valor and the label of the radio button would change. Home // Soon after the daily to Brasilia has value of 250.30 and the interior is fixed for all the states 160.00. Home At this point I would need to make the account I imagine with IFs for each capital and multiply with the value of the daily element of the radio button up there.

That was the way I thought. Would I have to do this or any other way in which I would achieve the same result? That is to have the name of the capital to be able to record in the database, and the amount of capital to make the account with the daily. How could I do this in Json or Javascript?

    
asked by anonymous 09.04.2014 / 09:36

1 answer

0

Look, see if this is what you want?

[EDIT] You have an update with the whole problem here: link Check if this is what you wanted, anything is just ask.

<input id="d1" required="required" value="1" name="diaria" type="radio">  
<label id="diaria" for="diaria">Uma diária</label> 

<input id="d2" required="required" value="2" name="diaria" type="radio">  
<label id="diaria" for="diaria">Duas diárias</label> 

<input id="d3" required="required" value="3" name="diaria" type="radio">  
<label id="diaria" for="diaria">Três diária</label> 
<br>

<select name="estado" id="estado" onChange="trocaEstado();">
   <option id="nenhum"  value="0"  > Escolher         </option>
   <option id="DF"      value="250"> Distrito Federal </option>
   <option id="SP"      value="200"> São Paulo        </option>
   <option id="outros"  value="300"> Outros Estados   </option>
</select>
<br>

<input id="input_capital" required="required" value="0" name="capital" type="radio" >  
<label id="capital" for="capital">Escolher</label> 
<input id="input_interior" required="required"  value="160" name="capital" type="radio">
<label id="interiror" for="capital">Interior</label>
<br>
<br>

<label for="resultado">Resultado</label> 
<input readonly="readonly" id="resultado" value="Zero"></input>
<br>
<!--input para o estado -->
<label for="estado_s">Estado</label> 
<input readonly="readonly" id="estado_s" value="nenhum"></input>    

<script>

function trocaEstado()
{
    var e        = document.getElementById("estado");
    var strcap   = e.options[e.selectedIndex].text;
    var strvalue = e.options[e.selectedIndex].value;

    //vai buscar o id da option
    var estado_s = e.options[e.selectedIndex].id;


    document.getElementById('input_capital').value=strvalue;
    document.getElementById('input_capital').checked=false;
    document.getElementById('capital').innerHTML=strcap;

    //mete o id da option no input estado_s
    document.getElementById('estado_s').value=estado_s;

}

 $(document).ready(function() {
    var capital=null;
    var diaria=null;
    $('input:radio[name=capital]').change(function() {
       capital = this.value;
       if(diaria)
           document.getElementById('resultado').value=(capital*diaria);
    });
    $('input:radio[name=diaria]').change(function() {
       diaria = this.value;
       if(capital)
           document.getElementById('resultado').value=(capital*diaria);
    });
});

</script>
    
09.04.2014 / 11:53