hi there,
i generated a form with address data. OnSubmit i will the adress convert to Google maps marker Location and put the value in a hidden box. the custom code is on first in On Submit but the script isnt running. is it a bug?
also simple scripts like alert('Hello'); arent work
any Ideas to run the script at onSubmit?
thanks
René
here are the script:
the Google maps ini js file is loading in the header
i generated a form with address data. OnSubmit i will the adress convert to Google maps marker Location and put the value in a hidden box. the custom code is on first in On Submit but the script isnt running. is it a bug?
also simple scripts like alert('Hello'); arent work
any Ideas to run the script at onSubmit?
thanks
René
here are the script:
<script>
var adresse = document.getElementById('input_text_21_ra').value + " " + document.getElementById('input_text_22_ra').value + "," + document.getElementById('input_text_5_ra').value + " " + document.getElementById('input_text_23_ra').value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{
'address': adresse
},
function(results){document.getElementById('input_LatLng_26_ra').value = results[0].geometry.location;}
);
</script>
the Google maps ini js file is loading in the header
Hi Réné,
If you load the script in the ON Submit event it will only be loaded with the Thank You page. Is that what you intend?
If so, do the inputs exist in the Thank You page HTML?
Bob
If you load the script in the ON Submit event it will only be loaded with the Thank You page. Is that what you intend?
If so, do the inputs exist in the Thank You page HTML?
Bob
Hi Bob,
thanks for getting back to me.
no i wont an thank you page. i Need to convert the normal address (multirow: street, number, City code and City Name) to an other Format (Google Map Marker Format: longitude, latitude) and set the hidden box with this new value and save all datas in the database. then the user get a normal notice. your entry is saved..
--------------------
update: i tried with the thank you page. but also document.getelementbyid doesnt work.
i put the datas in a new Input element, but the script wont work... cf_id isnt showing..
thanks for getting back to me.
no i wont an thank you page. i Need to convert the normal address (multirow: street, number, City code and City Name) to an other Format (Google Map Marker Format: longitude, latitude) and set the hidden box with this new value and save all datas in the database. then the user get a normal notice. your entry is saved..
--------------------
update: i tried with the thank you page. but also document.getelementbyid doesnt work.
i put the datas in a new Input element, but the script wont work... cf_id isnt showing..
<input id="adresse" value="{input_text_21_ra} {input_text_22_ra}, {input_text_5_ra} {input_text_23_ra}">
<div id="entry">{cf_id}</div>
<script>
var adresse = document.getelementbyid("adresse").value;
alert(adresse);
</script>
Hi locke28 ,
I'm sorry but I'm lost.
If you want to do this conversion and save the results then either (a) do it in the form with JavaScript in the ON Load event and add the results to hidden inputs or (b) do it with PHP in the On Submit event and add the results to the $form->data array.
Bob
I'm sorry but I'm lost.
If you want to do this conversion and save the results then either (a) do it in the form with JavaScript in the ON Load event and add the results to hidden inputs or (b) do it with PHP in the On Submit event and add the results to the $form->data array.
Bob
Hi Bob,
do you have an example? i tought On Load is only for the form to loading. all fields are empty. how can i get the Information to convert the address and bevor the user click on the submit button? i tried On Change or On Click but these Events arent working
---------------------------
update: i tried custom code under on submit.. and it doesnt work.. :-/
i simple test but no alert is showing.
do you have an example? i tought On Load is only for the form to loading. all fields are empty. how can i get the Information to convert the address and bevor the user click on the submit button? i tried On Change or On Click but these Events arent working
---------------------------
update: i tried custom code under on submit.. and it doesnt work.. :-/
i simple test but no alert is showing.
<script>
var adresse = <?php echo $form->data['input_text_21_ra'] . " " . $form->data['input_text_22_ra'] . ", " . $form->data['input_text_5_ra'] . " " $form->data['input_text_23_ra']; ?>
alert(adresse);
</script>
<script>
var adresse = "<?php echo $form->data['input_text_21_ra'] . ' ' . $form->data['input_text_22_ra'] . ', ' . $form->data['input_text_5_ra'] . ' ' . $form->data['input_text_23_ra']; ?>";
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{
'address' : adresse
},
function(results, status){
alert(status);
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
document.getElementById('input_LatLng1_26_ra').value = lat;
document.getElementById('input_LatLng2_26_ra').value = lng;
});
alert(lat + " " + lng);
</script>
this code works in On Load.. but the fields are empty.. how can i generate an Event like on Change or OnClick submit Button?
is it right that is impossible to set a function in custom code on On Load? if i set one than the Cronoforms Crash.. if i delete function and than the form is showing?!
it sucks.. i dont find a right way..🤨
it sucks.. i dont find a right way..🤨
I had exactly the same problem last days.
I understood something important : the submit event stops everything on the form,so if you make a click event on the submit button ,it will stop on the beginning.in addition,there is no connection of variables between the "on load" section and the "on submit" section-every one of them has its own scope.
my only solution right now is to change the type of the submit button from "submit" to "button"-this will prevent the submit event to occur and you can take the fields you want from your inputs(select for example). the problem in this solution is you can't use the forms advantages when you clicked the button because you can't use the submit event anymore. for example ,you can't update the db after finish the process. I think that's a shame there is no good basic tutorial here for this because many people asks about it and it takes a lot of time to understand it by yourself without a reason.
that's my code :
html code for my select and the button:
js code in the onload:
I understood something important : the submit event stops everything on the form,so if you make a click event on the submit button ,it will stop on the beginning.in addition,there is no connection of variables between the "on load" section and the "on submit" section-every one of them has its own scope.
my only solution right now is to change the type of the submit button from "submit" to "button"-this will prevent the submit event to occur and you can take the fields you want from your inputs(select for example). the problem in this solution is you can't use the forms advantages when you clicked the button because you can't use the submit event anymore. for example ,you can't update the db after finish the process. I think that's a shame there is no good basic tutorial here for this because many people asks about it and it takes a lot of time to understand it by yourself without a reason.
that's my code :
html code for my select and the button:
<select size="1" class="" title=""
type="select" id="input_select_1">
<option value="1,4,#,#,#,#,1,2">תמיכה טכנית בטלויזיה</option>
<option value="1,4,#,#,#,#,1,1">תמיכה טכנית בשלט</option>
</select></br>
<input id="input_submit_tv1" class="" value="הזמן שיחה" type="button" />//here I changed the type of the button
js code in the onload:
window.addEvent('domready', function() {
mySubmitButton=document.getElementById("input_submit_tv1");
mySubmitButton.addEvent('click', startCall);
});
function display(){
alert("display()");
}
function startCall(){
alert("startCall");
display();
var x=document.getElementById("input_select_1").selectedIndex ;//get the input index
alert("x.selected= "+x);
var y=$('input_select_1').value;//get the input value
alert(y);
}
Hi giladl1 & Flocke28,
I have no real idea what either of you are trying to do?
You can add as many Custom Code actions in the On Load or On Submit events of your form as you like; if one of them is crashing the form then there is probably a bug in your code.
Use Custom Code actions for PHP which is to be run on the server (before the form loads in the On Load event; or after the form Submits on the On Submit event).
Use Load JS actions for JavaScript which runs in the browser; 99% of this time this is only used in the On Load action (though it will also work in the On Submit event if you want to run scripts in a Thank You or confirmation Page).
There can be a timing problem if you link events to the Submit button because the ChronoForms form validation code is also triggered by the onSubmit event. There are ways round this if necessary but usually it's best to trigger your scripts from changes in the other form inputs. So I would run a Google Maps lookup linked to the address input - probably using the onBlur event.
The actions and events do have separate scopes. You can share variables between actions in the same event using the $form->data array. You can share data between the On Load and On Submit events either by adding hidden form inputs; or by saving the variables to the Joomla! User Session in the On Load event and recovering it in the On Submit event (the Data to Session & Session to Data actions do this).
You can't use JavaScript (as in one of Flocke's examples) mixed with PHP, the two run in separate locations at different times. You can though use PHP to create JavaScript that will later be run in the browser.
@giladl1: An input of type='button' is not a submit button but you can attach JavaScript actions to it. I can't make out what you are trying to do so can't offer more specific help.
Bob
I have no real idea what either of you are trying to do?
You can add as many Custom Code actions in the On Load or On Submit events of your form as you like; if one of them is crashing the form then there is probably a bug in your code.
Use Custom Code actions for PHP which is to be run on the server (before the form loads in the On Load event; or after the form Submits on the On Submit event).
Use Load JS actions for JavaScript which runs in the browser; 99% of this time this is only used in the On Load action (though it will also work in the On Submit event if you want to run scripts in a Thank You or confirmation Page).
There can be a timing problem if you link events to the Submit button because the ChronoForms form validation code is also triggered by the onSubmit event. There are ways round this if necessary but usually it's best to trigger your scripts from changes in the other form inputs. So I would run a Google Maps lookup linked to the address input - probably using the onBlur event.
The actions and events do have separate scopes. You can share variables between actions in the same event using the $form->data array. You can share data between the On Load and On Submit events either by adding hidden form inputs; or by saving the variables to the Joomla! User Session in the On Load event and recovering it in the On Submit event (the Data to Session & Session to Data actions do this).
You can't use JavaScript (as in one of Flocke's examples) mixed with PHP, the two run in separate locations at different times. You can though use PHP to create JavaScript that will later be run in the browser.
@giladl1: An input of type='button' is not a submit button but you can attach JavaScript actions to it. I can't make out what you are trying to do so can't offer more specific help.
Bob
This topic is locked and no more replies can be posted.