I want something like when I select a value on the drop-down list, that particular value has to show on my submit button. Please check the link below for what I mean https://www.elefant-tours.de/ueber-uns/reiseanmeldung/?wetu_id=15FAC4B2-C939-4179-918D-E3140BA3177E
CodePudding user response:
Example of that behavior with jquery.
You need to match the select id
and also insert a span tag inside the button with a matching class
Live example:
https://jsfiddle.net/1qjvtc86/
From gravityforms site:
there is an easy way to add custom Javascript to your Gravity Forms that only loads when the form is rendered. Just copy-and-paste your desired snippet into the robust editor on your Form Settings and you’re golden.
<div>
<select id="picker">
<option value="5">5 items</option>
<option value="4">4 items</option>
<option value="3">3 items</option>
<option value="2">2 items</option>
<option value="1">1 items</option>
</select>
</div>
<div>
<button>user picked <span >1</span> items</button>
</div>
<!-- copy this into gravity form -->
<script>
// picker - is the ID of the select
// pickedAmount - is the CLASS of the span
jQuery(function($){
$('#picker').on('change', function() {
$('.pickedAmount').text($(this).val());
})
});
</script>
<!-- copy this into gravity form -->
CodePudding user response:
Your JavaScript solution is:
<select onchange="my_fun(this)">
<option>item one(1)</option>
<option>item two(2)</option>
<option>item three(3)</option>
</select>
<script>
function my_fun(obj){
alert(obj.options[obj.selectedIndex].text);
}
</script>