Insert Dropdown Labels

Home Forums Quform WordPress Insert Dropdown Labels

This topic is: resolved
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #7160
    lawrencepepper
    Participant

    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

    #7168
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #7174
    lawrencepepper
    Participant

    Can 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

    #7175
    lawrencepepper
    Participant

    If possible, any help with the script would be appreciated.

    Thanks!

    #7178
    lawrencepepper
    Participant

    I 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();

    }
    );
    }
    );

    #7182
    lawrencepepper
    Participant

    Tried 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.

    #7200
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #7217
    lawrencepepper
    Participant

    Hi,

    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

    #7218
    lawrencepepper
    Participant

    Somehow 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

    #7219
    lawrencepepper
    Participant

    OK 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

    #16825
    movisart
    Participant

    can’t see

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy