How set hidden value by js script

danielitob 04 Apr, 2018
Hi,
i have a problem with chronoforms V6. In V5, i have 3 hidden fields populate as follow:

1) i have a check box with event "Check" that call a function, called "getdata".
2) Under Setup, "On Load", i have a "load javascript" action with the code:[pre]function getdata(){
var indirizzo = document.getElementById("indirizzo").value;
var comune = document.getElementById("comune").value;
var nome = document.getElementById("nome").value;

link = link.concat(comune,'/',nome);
document.getElementById("link").value=link; [mark]//SET FIRST HIDDEN VALUE [/mark]

var postData = {
"indirizzo" : indirizzo,[br] "comune" : comune[br] };[br][br] jQuery.ajax({[br] url: "/getCoordinatesFromAddress.php"[br] ,data: postData[br] ,type: "POST"[br] ,contentType: "application/json"[br] ,dataType : "json"[br] }).done(function( json ) {[br] jQuery('#lat').val(json.lat);[mark]//SET SECOND HIDDEN VALUE [/mark][br] jQuery('#lng').val(json.lng);[mark]//SET THIRD HIDDEN VALUE [/mark][br] }).fail(function (jqXHR, textStatus,errorThrown) {[br] alert("Errore"+textStatus+"--> status: "+jqXHR.status+ "\nerrorThrown: " + errorThrown);[br] });[br]}[/pre][br]In V6, I have my checkbox , I should set an event on Checked , under Events, and create the event under Setup and put this JS code with custom Code...but i can add only php code. [br]How can i do in V6?[br]These 3 hidden fields must be inserted into a table together with the other fields of the form[br][br]PS if is possible, this logic js could be added also when the form was submitted...i hope u can help me[br][br]regards[br]Daniele[br]
GreyHead 04 Apr, 2018
Hi Daniele,

In CFv6 the Javascript element is now in the Designer tab Custom group.

Bob
danielitob 04 Apr, 2018
Hi Bob,
yes, i know.
I 've put the js code in javascript element but i don't know how can i set an event on "Checked event" of my checkbox which call the funcion js , that i have in javascript element.
regards
GreyHead 04 Apr, 2018
Hi Daniele,

In the Checkbox element open the Events tab and select Function in the Actions box - I think you can then add the function name in the Element(s) identifier box.

Bob
danielitob 04 Apr, 2018
Hi Bob,
it's ok, great!.
How can i insert the 3 hidden fields into a table together with the other fields of the form?
Regards
GreyHead 04 Apr, 2018
Hi Daniele,

The values will be with the other form data - you can use HTML to show them. Where do you want the table to be?

Bob
danielitob 05 Apr, 2018
Hi,
i used HTML field (under custom) and i have put 3 hidden value, for example:
<input name="lng" id="lng" value="" type="hidden">
In Save Data action , i have set "Auto manage the data table", so all my fields , which have the check "Save to database" checked, will be store in my table. The fields, which are in "HTML" field, should be inserted in Save Data action in "Data Provider" field? If so, i can add all these 3 fields or i have to add all the form's fields? In what format should they be written?

Thanks very much

Regards
GreyHead 05 Apr, 2018
Hi Daniele,

If you use Hidden Field elements from the Extras elements group then CF should automatically add and save the data. I'm not sure about HTML elements - you may need to add those as new columns in the table to get them saved.

Bob
danielitob 05 Apr, 2018
Hi Bob, perfect. I 'll buy the extension so i can use more than 15 fields.
Thanks
Daniele
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger