Forums

Field not updated

Janovski 13 Dec, 2010
Hello,

I have done a form with this script who is autofilling some fields:
function calculate()
{
if ($('radio00').checked){$('je').value="SR";};
if ($('radio01').checked){$('je').value="PD";};

if ($('radio10').checked){$('ve').value="SR";};
if ($('radio11').checked){$('ve').value="BD";};
if ($('radio12').checked){$('ve').value="SV";};
if ($('radio13').checked){$('ve').value="PD";};

if ($('radio20').checked){$('sa').value="BD";};
if ($('radio21').checked){$('sa').value="SR";};
if ($('radio22').checked){$('sa').value="SA";};
if ($('radio23').checked){$('sa').value="DA";};
if ($('radio24').checked){$('sa').value="SV";};
if ($('radio25').checked){$('sa').value="PD";};
}


When I fill the form for the first time, there is no problem. But when I want to change my form the three hidden fields 'je', 've' and 'sa' are not updated!

What is wrong?

Thanks for advice
GreyHead 13 Dec, 2010
Hi janovski,

There is no event here to trigger the function when the radio buttons change. It will be something like
$('radio10').addEvent('click', calculate);
Rather than add one for each radio button you may be able to add the event to a wrapping tag for a whole group - that depends how your HTML is structured.

Bob
Janovski 13 Dec, 2010
In the HTML code there is already an event to trigger the function like

      <input value="SR" title="" class="radio" id="radio00" name="jeudi" type="radio" onChange="calculate()"/>
      <label for="radio00" class="radio_label">Aménagement du parcours à ski de rando</label>
      <br />


The first time I fill the form, the value are right filled, but not when I edit the form after! Even if these values are shown on the form. I see that the values are updated when I click on a radio, but not changed in the DB!
GreyHead 13 Dec, 2010
Hi janovski ,

I don't understand why editing would make a difference? Please post a link to the form so we can take a quick look.

Bob
Janovski 14 Dec, 2010
Here is the Form Code:

<div class="form_item">
  <div class="form_element cf_heading">
    <h1 class="cf_text">Inscription bénévole Torgon Skialpi</h1>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Nom</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_1" name="nom" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Prénom</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_2" name="prenom" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Adresse</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_3" name="adresse" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Numero postal</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_4" name="npa" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Lieu</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_5" name="lieu" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Nr de tél. mobile</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_6" name="num_mobile" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Email</label>
    <input class="cf_inputbox required validate-email" maxlength="150" size="30" title="" id="text_7" name="email" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_heading">
    <h2 class="cf_text">Disponibilités</h2>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">20.01 Jeudi</label>
<br />
<br />

      <input value="Amenagement du parcours à ski de rando" title="" class="radio" id="radio00" name="jeudi" type="radio" onChange="calculate()"/>
      <label for="radio00" class="radio_label">Aménagement du parcours à ski de rando</label>
      <br />
      
<input value="Pas disponible" title="" class="radio" id="radio01" name="jeudi" type="radio" onChange="calculate()"/>
      <label for="radio01" class="radio_label">Pas disponible</label>
      <br />
      


    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">21.01 Vendredi</label>
<br />
<br />

      <input value="Amenagement du parcours à ski de rando" title="" class="radio" id="radio10" name="vendredi" type="radio" onChange="calculate()"/>
      <label for="radio10" class="radio_label">Aménagement du parcours à ski de rando</label>
      <br />
      
<input value="Bureau des dossards à Vionnaz en fin d'apres-midi" title="" class="radio" id="radio11" name="vendredi" type="radio" onChange="calculate()"/>
      <label for="radio11" class="radio_label">Bureau des dossards à Vionnaz en fin d'après-midi</label>
      <br />
      
<input value="Amenagement de la salle de Vionnaz le soir" title="" class="radio" id="radio12" name="vendredi" type="radio" onChange="calculate()"/>
      <label for="radio12" class="radio_label">Aménagement de la salle de Vionnaz le soir</label>
      <br />
      
<input value="Pas disponible" title="" class="radio" id="radio13" name="vendredi" type="radio" onChange="calculate()"/>
      <label for="radio13" class="radio_label">Pas disponible</label>
      <br />
      


    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">22.01 Samedi</label>
<br />
<br />

      <input value="Bureau des dossards à Vionnaz le matin" title="" class="radio validate-one-required" id="radio20" name="samedi" type="radio" onChange="calculate()"/>
      <label for="radio20" class="radio_label">Bureau des dossards à Vionnaz le matin</label>
      <br />
      
<input value="Commissaire sur le parcours à ski de rando" title="" class="radio validate-one-required" id="radio21" name="samedi" type="radio" onChange="calculate()"/>
      <label for="radio21" class="radio_label">Commissaire sur le parcours à ski de rando (matériel de sécurité DVA-pelle-sonde perso obligatoire!)</label>
      <br />
      
<input value="Commissaire sur le parcours à ski" title="" class="radio validate-one-required" id="radio22" name="samedi" type="radio" onChange="calculate()"/>
      <label for="radio22" class="radio_label">Commissaire sur le parcours à ski (partie empruntant les pistes)</label>
      <br />
      
<input value="Poste sur la place de depart/arrivee" title="" class="radio validate-one-required" id="radio23" name="samedi" type="radio" onChange="calculate()"/>
      <label for="radio23" class="radio_label">Poste sur la place de départ/arrivée</label>
      <br />
      
<input value="Poste à la cantine à Vionnaz" title="" class="radio validate-one-required" id="radio24" name="samedi" type="radio" onChange="calculate()"/>
      <label for="radio24" class="radio_label">Poste à la cantine à Vionnaz</label>
      <br />
      
<input value="Pas disponible" title="" class="radio validate-one-required" id="radio25" name="samedi" type="radio" onChange="calculate()"/>
      <label for="radio25" class="radio_label">Pas disponible</label>
      <br />
      

    
  </div>
  <div class="cfclear"> </div>
</div>

<input value="" id="hidden_16" name="responsable" type="hidden" />

<input value="" id="je" name="je" type="hidden" onChange="calculate()" />

<input value="" id="ve" name="ve" type="hidden" onChange="calculate()" />

<input value="" id="sa" name="sa" type="hidden" onChange="calculate()" />

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Remarques</label>
    <textarea class="cf_inputbox" rows="3" id="text_14" title="" cols="30" name="remarque"></textarea>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Valider le formulaire" name="button_15" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


The JS Code
function calculate()
{
if ($('radio00').checked){$('je').value="SR";}
if ($('radio01').checked){$('je').value="PD";}

if ($('radio10').checked){$('ve').value="SR";}
if ($('radio11').checked){$('ve').value="BD";}
if ($('radio12').checked){$('ve').value="SV";}
if ($('radio13').checked){$('ve').value="PD";}

if ($('radio20').checked){$('sa').value="BD";}
if ($('radio21').checked){$('sa').value="SR";}
if ($('radio22').checked){$('sa').value="SA";}
if ($('radio23').checked){$('sa').value="DA";}
if ($('radio24').checked){$('sa').value="SV";}
if ($('radio25').checked){$('sa').value="PD";}
}


And a link to the backuped form:

http://skialpi.torgon.net/files/inscrip_benevoles.cfbak

When I edit the form some of the radio fields are not checked to!

Thank for your help!
GreyHead 14 Dec, 2010
Hi janovski,

I've spent a while looking at your form. It seems to me to work OK. I'm afraid that I don't understand what the problem is that you are seeing.

Bob
This topic is locked and no more replies can be posted.