- Posts: 18
- Thank you received: 4
Ask the community, share ideas, and connect with other LimeSurvey users!
Self : {self} <script> $(document).ready(function(){ var whatiwant = "this is what I want"; $("#answer714997X7X98").val(whatiwant); }); </script>
<script> $(document).ready(function(){ var whatiwant = "this is what I want"; $("#answer{SGQ}").val(whatiwant).trigger('keyup'); }); </script>
Self : {self} <p>SGQ: {SGQ}</p> <input id="text" name="text" type="text" /> <script> $(document).ready(function(){ $("#text").keyup(function() { var whatiwant = document.getElementById("text"); document.getElementById("answer{SGQ}").value = whatiwant.value; }); $("#answer{SGQ}").trigger('keyup'); }); </script>
<label>Di manakah Anda tinggal?</label> <p>x3 alamat: {355481X12X92y0_x3}</p> <div class="ls-answers answer-item text-item "><input class="form-control " id="mailcompletegeser" style="" type="text" value="" /></div> <script src="https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=AIzaSyD0v6cdUflFKKxeUzzQWn1t2kriR57nf1s"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script src="https://ubilabs.github.io/geocomplete/jquery.geocomplete.js"></script> <div id="map_canvas" style="width:100%; height: 350px;"> </div> <script> $(document).ready(function(){ document.getElementById("answer355481X12X92y0_x0").readOnly = true; document.getElementById("answer355481X12X92y0_x1").readOnly = true; document.getElementById("answer355481X12X92y0_x2").readOnly = true; document.getElementById("answer355481X12X92y0_x3").readOnly = true; var options = { country: ["ID"], types: ['geocode','establishment'], map: "#map_canvas", location: [-6.17511, 106.86503949999997], mapOptions: { zoom: 10, streetViewControl: false, fullscreenControl: false, mapTypeControl: false }, markerOptions: { draggable: true } }; $("#mailcompletegeser").geocomplete(options).bind("geocode:result", function(event, result){ var map = $("#mailcompletegeser").geocomplete("map"); var pcd = ""; for(var i=0; i < result.address_components.length; i++){ var component = result.address_components[i]; if(component.types[0] == "postal_code") { pcd = component.long_name; } } $("#answer355481X12X92y0_x0").val(result.geometry.location.lat()).trigger('keyup'); $("#answer355481X12X92y0_x1").val(result.geometry.location.lng()).trigger('keyup'); $("#answer355481X12X92y0_x2").val(pcd).trigger('keyup'); $("#answer355481X12X92y0_x3").val(result.formatted_address).trigger('keyup'); }); $("#mailcompletegeser").bind("geocode:dragged", function(event, latLng){ var map = $("#mailcompletegeser").geocomplete("map"); map.panTo(latLng); var geocoder = new google.maps.Geocoder(); $("#answer355481X12X92y0_x0").val(latLng.lat()); $("#answer355481X12X92y0_x1").val(latLng.lng()); geocoder.geocode({'latLng': latLng }, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { for(var i=0; i < results[0].address_components.length; i++){ var carikodepos = results[0].address_components[i]; if(carikodepos.types[0] == "postal_code"){ $("#answer355481X12X92y0_x2").val(carikodepos.long_name); } } var alamat = results[0].formatted_address; $("#answer355481X12X92y0_x3").val(alamat); $("#mailcompletegeser").val(alamat); } }); $("#answer355481X12X92y0_x3").trigger('keyup'); }); }); </script>
I have already explained how to do that above.Basicly, I need to copy the values to Limesurvey's text input and make Limesurvey recognize the value/input.
$("#answer{SGQ}SQ001").val(result.geometry.location.lat()).trigger('keyup');
//this does not seem to work, the value of the text field do not change :( $("#answer{SGQ}SQ003").val(carikodepos.long_name).trigger('keyup');
<label>Where do you live?</label> <!--to show what the answer looks like--> <p>self: {self}</p> <p>SQ001: {yourhome_SQ001}</p> <p>SQ002: {yourhome_SQ002}</p> <p>SQ003: {yourhome_SQ003}</p> <p>SQ004: {yourhome_SQ004}</p> <!--Show input text field for address using Limesurvey style--> <div class="ls-answers answer-item text-item "> <input class="form-control " id="mailcompletegeser" style="" type="text" value="" /> </div> <!--Division for the map canvas--> <div id="map_canvas" style="width:100%; height: 350px;"> </div> <!--call necessary scripts--> <script src="https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=AIzaSyD0v6cdUflFKKxeUzzQWn1t2kriR57nf1s"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="https://ubilabs.github.io/geocomplete/jquery.geocomplete.js"></script> <!--the script that uses geocomplete and insert the values to answer field--> <script> $(document).ready(function(){ //Make the answer text field unavailable for user to change the value document.getElementById("answer{SGQ}SQ001").readOnly = true; document.getElementById("answer{SGQ}SQ002").readOnly = true; document.getElementById("answer{SGQ}SQ003").readOnly = true; document.getElementById("answer{SGQ}SQ004").readOnly = true; //declare and initialize map named 'options' var options = { country: ["ID"], types: ['geocode','establishment'], map: "#map_canvas", location: [-6.17511, 106.86503949999997], mapOptions: { zoom: 10, streetViewControl: false, fullscreenControl: false, mapTypeControl: false }, markerOptions: { draggable: true } }; //what to do when the user inputs address and uses the geocomplete form $("#mailcompletegeser").geocomplete(options).bind("geocode:result", function(event, result){ var map = $("#mailcompletegeser").geocomplete("map"); var pcd = ""; for(var i=0; i < result.address_components.length; i++){ var component = result.address_components[i]; if(component.types[0] == "postal_code") { pcd = component.long_name; } } //input the values to the limesurvey's answer field $("#answer{SGQ}SQ001").val(result.geometry.location.lat()).trigger('keyup'); $("#answer{SGQ}SQ002").val(result.geometry.location.lng()).trigger('keyup'); $("#answer{SGQ}SQ003").val(pcd).trigger('keyup'); $("#answer{SGQ}SQ004").val(result.formatted_address).trigger('keyup'); }); //what to do when user drags the marker on map $("#mailcompletegeser").bind("geocode:dragged", function(event, latLng){ var map = $("#mailcompletegeser").geocomplete("map"); map.panTo(latLng); var geocoder = new google.maps.Geocoder(); $("#answer{SGQ}SQ001").val(latLng.lat()).trigger('keyup'); $("#answer{SGQ}SQ002").val(latLng.lng()).trigger('keyup'); geocoder.geocode({'latLng': latLng }, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { for(var i=0; i < results[0].address_components.length; i++){ var carikodepos = results[0].address_components[i]; if(carikodepos.types[0] == "postal_code"){ //this does not seem to work, the value of the text field do not change :( $("#answer{SGQ}SQ003").val(carikodepos.long_name).trigger('keyup'); } } var alamat = results[0].formatted_address; //neither does this one, it does not change the text field $("#answer{SGQ}SQ004").val(alamat).trigger('keyup'); $("#mailcompletegeser").val(alamat); } }); }); }); </script>
<p><strong>Where do you live?</strong></p> <!--to show what the answer looks like--> <p>self: {self}</p> <p>SQ001: {yourhome_SQ001}</p> <p>SQ002: {yourhome_SQ002}</p> <p>SQ003: {yourhome_SQ003}</p> <p>SQ004: {yourhome_SQ004}</p> <!--Division for the map canvas--> <div id="map_canvas" style="width:100%; height: 350px; margin: 20px 0;"> </div> <!--call necessary scripts--> <script src="https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=yourKey"></script> <script src="https://ubilabs.github.io/geocomplete/jquery.geocomplete.js"></script> <!--the script that uses geocomplete and insert the values to answer field--> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Move the canvas $('#question{QID} .answer-container').append($('#map_canvas')); //Make the answer text field unavailable for user to change the value document.getElementById("answer{SGQ}SQ001").readOnly = true; document.getElementById("answer{SGQ}SQ002").readOnly = true; document.getElementById("answer{SGQ}SQ003").readOnly = true; //document.getElementById("answer{SGQ}SQ004").readOnly = true; //declare and initialize map named 'options' var options = { country: ["ID"], types: ['geocode','establishment'], map: "#map_canvas", location: [-6.17511, 106.86503949999997], mapOptions: { zoom: 10, streetViewControl: false, fullscreenControl: false, mapTypeControl: false }, markerOptions: { draggable: true } }; //what to do when the user inputs address and uses the geocomplete form $("#answer{SGQ}SQ004").geocomplete(options).bind("geocode:result", function(event, result){ var map = $("#answer{SGQ}SQ004").geocomplete("map"); var pcd = ""; for(var i=0; i < result.address_components.length; i++){ var component = result.address_components[i]; if(component.types[0] == "postal_code") { pcd = component.long_name; } } //input the values to the limesurvey's answer field $("#answer{SGQ}SQ001").val(result.geometry.location.lat).trigger('keyup'); $("#answer{SGQ}SQ002").val(result.geometry.location.lng).trigger('keyup'); $("#answer{SGQ}SQ003").val(pcd).trigger('keyup'); $("#answer{SGQ}SQ004").val(result.formatted_address).trigger('keyup'); }); //what to do when user drags the marker on map $("#answer{SGQ}SQ004").bind("geocode:dragged", function(event, latLng){ var map = $("#answer{SGQ}SQ004").geocomplete("map"); map.panTo(latLng); var geocoder = new google.maps.Geocoder(); $("#answer{SGQ}SQ001").val(latLng.lat).trigger('keyup'); $("#answer{SGQ}SQ002").val(latLng.lng).trigger('keyup'); geocoder.geocode({ 'latLng': latLng }, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { for(var i=0; i < results[0].address_components.length; i++){ var carikodepos = results[0].address_components[i]; if(carikodepos.types[0] == "postal_code"){ $("#answer{SGQ}SQ003").val(carikodepos.long_name).trigger('keyup'); } } var alamat = results[0].formatted_address; $("#answer{SGQ}SQ004").val(alamat).trigger('keyup'); } }); }) }); </script>