Home › Forums › Quform WordPress › Insert Dropdown Labels
- This topic has 10 replies, 3 voices, and was last updated 8 years, 8 months ago by movisart.
- AuthorPosts
- October 31, 2013 at 8:07 pm #7160lawrencepepperParticipant
I need to insert the Label as well as the Value from a dropdown on my form.
Have a drop down in which I have a Label and a custom Value, both need to be inserted into separate fields in my database. So for instance if the person chooses Vacation in the dropdown the value is 001. I need the label Vacation inserted into the Description field and the vale 001 inserted into my code field in my database table.
Inserting the value is obvious, how to get the label in?
Can this be done?
L
November 1, 2013 at 11:37 am #7168AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 1, 2013 at 1:19 pm #7174lawrencepepperParticipantCan this be done with javascript?
Would it be possible to insert a HTML element into the form with a javascript that sets a variable based on what was selected in the dropdown?
So say they select Vacation. The javascript would then set a variable named descritpion that had the value of Vacation, which I could then use to pass with the form and insert into the database?
L
November 1, 2013 at 1:26 pm #7175lawrencepepperParticipantIf possible, any help with the script would be appreciated.
Thanks!
- This reply was modified 10 years, 6 months ago by lawrencepepper.
- This reply was modified 10 years, 6 months ago by lawrencepepper.
November 1, 2013 at 1:37 pm #7178lawrencepepperParticipantI found this that basically does what I am asking, can it be adopted to work here:
$(document).ready(
function() {
$('select[name=package]').change(
function(){
var newText = $('option:selected',this).text();
$('#costLabel').text('Total price: ' + newText);
}
);
}
);guessing:
$(document).ready(
function() {
$('select[name=iphorm1_1]').change(
function(){
var description = $('option:selected',this).text();}
);
}
);- This reply was modified 10 years, 6 months ago by lawrencepepper.
- This reply was modified 10 years, 6 months ago by lawrencepepper.
November 1, 2013 at 3:43 pm #7182lawrencepepperParticipantTried this but still can not get to work.
<script type="text/javascript">
$(document).ready(
function() {
$('select[name=iphorm_1_1]').change(
function(){
var description = $('option:selected',this).text();}
);
}
);
</script>Thinking if I can get this script to work I can then insert a hidden field and have it’s default value be this variable. Then I can insert it into my database with the rest of the form data as I am doing now.
- This reply was modified 10 years, 6 months ago by lawrencepepper.
November 4, 2013 at 12:07 pm #7200AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 4, 2013 at 4:40 pm #7217lawrencepepperParticipantHi,
Getting close. That script sets the hidden field to the value. I need the label.
When I change the script to:
<script>
jQuery(document).ready(function ($) {
$('.iphorm_1_1').change(function () {
$('input[name="iphorm_1_14"]').val($(this).text());
}).change();
});
</script>
It works but it inserts all the labels from the dropdown, not just the one selected.
Any ideas?
L
November 4, 2013 at 4:52 pm #7218lawrencepepperParticipantSomehow I think this needs to be used so that we are setting the value to just the text label of what is chosen in the dropdown:
$('option:selected',this).text();
L
November 4, 2013 at 4:54 pm #7219lawrencepepperParticipantOK got it!
used this:
<script>
jQuery(document).ready(function ($) {
$('.iphorm_1_1').change(function () {
$('input[name="iphorm_1_14"]').val($('option:selected',this).text());
}).change();
});
</script>Thanks so much for the help!
L
September 14, 2015 at 4:34 pm #16825movisartParticipantcan’t see
- AuthorPosts
- You must be logged in to reply to this topic.