hi, sorry but I'm using chronoforms v6 for the first time.
I have 3 fields: fieldone, fieldtwo, fieldthree.
I would like to visualize in the following custom html:
the value "0" if all three fields are empty
the value "10" if only one is not empty
the value "20" if two are not empty
the value "30" if all three are not empty
how can I do?
Life Color Communication srl
Hi lifecolor,
You can write a small JavaScript function to set the value of a readonly text input. It would check the three inputs and set the value accordingly. You can then go to each of these three inputs open the settings, open the Events tab. Then set the 'triggering event' (the first box to Change, and the 'Triggered action' to the name of your JavaScript function.
Bob
Bob sorry but ...
in all field event
In Triggering event: Change
Triggered action (s): Function
Affected elements CSS selectors: namefunction
In content javascript ??
function namefunction () {
var value = 0;
if (fieldone! = "") {value = value + 10;}
if (fieldtwo! = "") {value = value + 10;}
if (fieldthree! = "") {value = value + 10;}
alert (value);
}
How do I call the "fieldone" field?
How can I write the value instead of the alert?
Life Color Communication srl
But I don't see the value box..
in this way when I start writing this field I call javascript.
but I don't know how to write the javascript that reads my data and writes the value
Life Color Communication srl
It's the box on the left that says possible value
ok..
but if i write namefunction on the left when i write in this field the alert does not work 😢
Life Color Communication srl
To get the values you use
jQuery('input[name="fieldnamegoeshere"]').val()
perfect..
function namefunction(){
var fieldone = jQuery('input[name="email_aggiuntiva"]').val();
var fieldtwo = jQuery('input[name="email_aggiuntiva2"]').val();
var fieldthree = jQuery('input[name="email_aggiuntiva3"]').val();
var fieldfour = jQuery('input[name="email_aggiuntiva4"]').val();
var fieldfive = jQuery('input[name="email_aggiuntiva5"]').val();
var valore = 0;
if (fieldone != ""){ valore = valore + 10; }
if (fieldtwo != ""){ valore = valore + 10; }
if (fieldthree != ""){ valore = valore + 10; }
if (fieldfour != ""){ valore = valore + 10; }
if (fieldfive != ""){ valore = valore + 10; }
alert(valore);
}
but.. now i would change the alert and write the value "valore" in a text html.
can you help me? 🙂
Life Color Communication srl
jQuery('#idOfTheHTMLBlock').html('The value is now ' + valore);
thank you so much !!!!!!!! 🤣🤣🤣
Life Color Communication srl
sorry .. last thing.
how do I print this value in the body of the email?
You can use HTML, text and chrono commands, e.g: {data:field_name}
Life Color Communication srl
Recalculate it again on submit using PHP. Return it from the php function and include it in your email using {var:php_block_name}
Sorry, but I did not understand😟
I have insert in submit - action a block php.
Name: php4
Code:
$mail1 = "{data:email_aggiuntiva}";
$mail2 = "{data:email_aggiuntiva2}";
$mail3 = "{data:email_aggiuntiva3}";
$mail4 = "{data:email_aggiuntiva4}";
$mail5 = "{data:email_aggiuntiva5}";
$valore = 390;
if ($mail1 != null) {$valore=$valore+250;}
if ($mail2 != null) {$valore=$valore+250;}
if ($mail3 != null) {$valore=$valore+250;}
if ($mail4 != null) {$valore=$valore+250;}
if ($mail5 != null) {$valore=$valore+250;}
echo $valore;
but in this way print a wrong value.
if I have an empty email the "if condition" nothing is not calculated well .. the final value is always 1640
and then...
instead of printing the value, how can I insert it in the body of the email?
{var: php4}
I see nothing
thanks
Life Color Communication srl
Can';t use shortcodes in PHP. Use $this->data('email_aggiuntiva')
perfect... thanks
Life Color Communication srl