you can create a form with a field of sum of multiple fields

riga75 10 Jun, 2011
Let's see if I can explain what I do.
my form in addition to "classical" fields name, surname, telephone, email, etc. must have an opportunity with two combo example: € 15 and then no other field with: 45 and no one, and so is another area where is the sum of the various fields.
I explained it well?
is this possible? if so, how?
thank you very much

stefano
GreyHead 10 Jun, 2011
Hi stefano,

You can do that with JavaScript. If you post the Forn HTML for the form so far then we can suggest some code JavaSCript for you.

Bob
riga75 10 Jun, 2011
I then use this form:

 <table width="470" border="0">
    
    
    <tr>
      <td width="150">Cognome e Nome</td>
      <td width="206"><input type="text" title="Inserire il proprio Cognome e Nome" class="validate['required']" name="CognomeNome" />*</td>
      <td width="100"> </td>
    </tr>
    <tr>
      <td>Località</td>
      <td><input type="text" name="Localita" /></td>
      <td> </td>
    </tr>
    
    <tr>
      <td>Telefono</td>
      <td><input type="text" title="Inserire il proprio Telefono (servirà in caso di chiarimenti)" class="validate['required','phone']" name="Telefono" />*</td>
      <td> </td>
    </tr>
    <tr>
      <td>Indirizzo email</td>
      <td><input type="text" title="Inserire un indirizzo Email corretto (serve per comunicarvi aggiornamenti)" class="validate['required','email']" name="Email" />*</td>
      <td> </td>
    </tr>
    
    
    <tr>
      <td>Note:</td>
      <td colspan="2" rowspan="2"><label>
        <textarea name="note" type="text" title="Inserire delle note, più dettagliate sono migliore sarà il nostro progetto" class="validate['required']" id="note" cols="25" rows="5"></textarea>
      </label>*</td>
      </tr>
    <tr>
      <td> </td>
    </tr>
    <tr>
      <td>Ambienti da progettare</td>
      <td><label>
        <select name="ambientidaprogettare" id="select">
        <option selected="selected">Seleziona una voce</option>
        <option value="1ambiente">1 Ambiente</option>
        <option value="2ambienti">2 Ambienti</option>
        <option value="3ambient">3 Ambienti</option>
        <option value="4ambient">4 Ambienti</option>
        <option value="5opiuambient">5 o più Ambienti</option>
        </select>
      </label></td>
      <td> </td>
    </tr>
    <tr>
      <td>Opzioni:</td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="3"><input type="checkbox" name="schemaimpianti" value="Si" />
       Schema impianti (35,00 €)</td>
      </tr>
    <tr>
      <td colspan="3"><input type="checkbox" name="planimetriadwg" value="Si" />
         Sconto 10% per planimetria in dwg  </td>
      </tr>
    <tr>
      <td colspan="3"><input type="checkbox" name="piuambienti" value="Si" />
         Sconto 15% per più di 5 ambienti</td>
      </tr>
    <tr>
      <td>Totale da pagare</td>
      <td><input name="totale" type="text" size="7" /> 
        €</td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="3"><label>Carica la Piantina</label>
        <input class="validate['required']" title="Caricare una piantina" type="file" name="input_file_6" />*</td>
      </tr>
   <tr align="center">
      <td colspan="3"><input type="submit" name="Submit" value="Invia" /> 
* = Campi obbligatori </td>
    </tr>
    <tr align="center">
      <td colspan="3">
        Fornisco l'autorizzazione al trattamento dei miei dati personali per ottemperare agli obblighi previsti dalla legge, dai regolamenti o dalla normativa comunitaria.
        <br />
        Presto il consenso al trattamento * 
        <input type="checkbox" class="validate['required']" title="Per inviare il form devi dare il consenso" name="privacy" value="Si" checked="checked" /></td>
    </tr>
  </table>


cosider that the total price is 65 € plus select whether or not any other options
thanks Bob
riga75 11 Jun, 2011
I uploaded the updated code on the form and you have to consider one thing Bob, the field list / menu if you select an environment, then you must set the value 65, if you select two environments then 130 etc and then I added the total field where they will be the total .
I hope I explained myself .... thank you
GreyHead 11 Jun, 2011
Hi stefano,

Here's the beginning of a script for you:
window.addEvent('domready', function() {
  $('ambientidaprogettare').addEvent('change', calc);
  $('schemaimpianti').addEvent('click', calc);
  $('planimetriadwg').addEvent('click', calc);    
});
function calc() {
  var prezzo = new Array();
  prezzo['1ambiente'] = 1;
  prezzo['2ambienti'] = 2;
  prezzo['3ambient'] = 3;
  prezzo['4ambient'] = 4;
  prezzo['5opiuambien'] = 0;
  var ambienti = $('ambientidaprogettare').value;
  var totale = 0;
  amb = prezzo[ambienti];
  if ( amb != NaN ) {
    totale = 65*amb;
  }
  if ( $('schemaimpianti').checked ) {
    totale = totale + 35;
  }
  if ( $('planimetriadwg').checked ) {
    totale = totale * 0.9;
  }
  $('totale').value = parseInt(totale);
};

To get this to work you need to add ids to the inputs used in the calculation e.g. id='ambientidaprogettare'.I've used the name as the id in each case.

There's also some missing information that you will need to work out how to handle: you can't calculate the price or discount for 'more than 5 rooms'.

Bob
riga75 11 Jun, 2011
sorry bob, but where I insert the code?
Thanks
GreyHead 11 Jun, 2011
Hi stefano,

To get this to work you need to add ids to the inputs used in the calculation e.g. id='ambientidaprogettare'. I've used the name as the id in each case.


Bob
riga75 11 Jun, 2011
here is perfect, that it was imagined that the problem but I did not understand what I do .... excuse my ignorance 😢
riga75 13 Jun, 2011
Sorry bob, but I tried several ways but I did not understand what to do.
Would you be kind enough to last me a help?
Thanks

stefano
GreyHead 13 Jun, 2011
Hi Stefano,

OK, first please post the Form HTML where you have added the ids.

Bob
riga75 13 Jun, 2011

Hi Stefano,

OK, first please post the Form HTML where you have added the ids.

Bob



The problem Bob is that I did not understand where I enter the ids,😟

stefano
GreyHead 13 Jun, 2011
Hi stefano,

Here for example
<select name="ambientidaprogettare" id="ambientidaprogettare">
or here
<input type="checkbox" name="schemaimpianti" id="schemaimpianti" value="Si" />


Bob
riga75 13 Jun, 2011
Fantastic Bob, you're a genius .....
GreyHead 13 Jun, 2011
Hi stefano,

Your Image Gallery is loading the jQuery JavaScript library. Out of the box jQuery isn't compatible with the MooTools library used by Joomla! and ChronoForms. You can use jQuery with MooTools in no-conflict mode. There are various ways of doing this. The simplest is to add a line of script in the ChronoForms Form JavaScript box:
jQuery.noConflict();
This will free the $ operator which is used by MooTools, so you may need to update your own javascripts to use the longer jQuery operator.

There is also a neat Joomla! system plugin named SC jQuery that allows you to control on which pages jQuery is loaded, and will always load it in no-conflict mode.

Bob
riga75 14 Jun, 2011
Unfortunately, the SC jQuery plugin does not work with joomla 1.6
I try to see if I can find some other gallery, you know recommend one?
I have to look for a ch efunzioni with jquery or with MooTools?
Thanks
GreyHead 14 Jun, 2011
Hi stefano,

I don't have a gallery to recommend - thre are several MooTools galleries around.

A pity that the SC JQuery plug-in doesn't work with Joomla! 1.6. I've just looked at the code and it's nicely done.

The essential part is this. You might be try including it in your code. It needs to run after JQuery is loaded but before any MooTools based javascript is run. The code snippet is
if (typeof jQuery !== 'undefined') {
	jQuery.noConflict();
}
which tests to see if JQuery is loaded before running the noConflict() command.

Bob
riga75 14 Jun, 2011
Sorry Bob, but where should I put the code?
I tried to put it in the Load JS does not work.
What's wrong?
thanks
GreyHead 14 Jun, 2011
Hi stefano,

Hard to say - it depends on how your template and the gallery plug-in are loading their code.

Bob
GreyHead 15 Jun, 2011
Hi Stefano,

Great - well done.

Bob
riga75 15 Jun, 2011
Thanks to you, without your help I would not be able to do
This topic is locked and no more replies can be posted.