Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:29:38+00:00 2026-06-10T15:29:38+00:00

hi so as the title implies im trying to get two values from a

  • 0

hi so as the title implies im trying to get two values from a select element.

what i have all ready set up is two select elements which upon selection of the first select filters the second, there are over 16000 items to filter on the second, i think i will probably need a better way to integrate this but anyway i need to get both the displayed name and the value from the select and create a second variable to hold the value so.

starting from the top this is the script that filters the values if anyone can point me in the direction of a good ajax tut to set all this up i would be greatfull this is my js

<script type="text/javascript">
//<![CDATA[
jQuery.fn.filterOn = function(selectFrom, values) {
    return this.each(function() {
        var select = this;
        var options = {};
$(select).find('option').each(function() {
    var $o = $(this), title = $o.attr('title');
    if (options.hasOwnProperty(title) === false) {
        options[title] = [];
    }
    options[title].push({ 'text': $o.text(), 'value': $o.val() });
});
$(select).data('options', options);
        console.log(selectFrom);
       $(selectFrom).change(function() {
    var $select = $(select),
        options = $select.empty().data('options')[$(this).val()];
    // options is now just an array of objects with value and text properties, so:
    $.each(options, function () {
        $('<option value="' + this.value + '">' + this.text + '</option>').appendTo($select);
    });
  }); 
  });
};

$(function() {
    $('#city').filterOn('#country', {
        'default': [],
        'LK':['LK'],'SY':['SY'],'KE':['KE'],'KH':['KH'],'MN':['MN'],'SN':['SN'],'JO':['JO'],'SE':['SE'],'GB':['GB'],'AT':['AT'],'IL':['IL'],'PY':['PY'],'JM':['JM'],'MX':['MX'],'CL':['CL'],'CA':['CA'],'BG':['BG'],'MC':['MC'],'PR':['PR'],'LB':['LB'],'EC':['EC'],'PW':['PW'],'GU':['GU'],'MK':['MK'],'RE':['RE'],'BW':['BW'],'LY':['LY'],'TG':['TG'],'TH':['TH'],'MY':['MY'],'ES':['ES'],'DK':['DK'],'DO':['DO'],'BZ':['BZ'],'NI':['NI'],'VE':['VE'],'LV':['LV'],'AZ':['AZ'],'MD':['MD'],'AE':['AE'],'MT':['MT'],'SZ':['SZ'],'YE':['YE'],'SV':['SV'],'MW':['MW'],'GF':['GF'],'BD':['BD'],'LI':['LI'],'SM':['SM'],'BY':['BY'],'MZ':['MZ'],'IR':['IR'],'PK':['PK'],'RU':['RU'],'MU':['MU'],'TW':['TW'],'PT':['PT'],'NG':['NG'],'GR':['GR'],'CH':['CH'],'KW':['KW'],'LU':['LU'],'CZ':['CZ'],'HR':['HR'],'AR':['AR'],'EG':['EG'],'CR':['CR'],'US':['US'],'LT':['LT'],'KZ':['KZ'],'RS':['RS'],'EE':['EE'],'SG':['SG'],'FM':['FM'],'AL':['AL'],'ML':['ML'],'UG':['UG'],'ZA':['ZA'],'MM':['MM'],'AU':['AU'],'FJ':['FJ'],'IT':['IT'],'AD':['AD'],'NO':['NO'],'BR':['BR'],'UY':['UY'],'GT':['GT'],'PF':['PF'],'SC':['SC'],'BB':['BB'],'ME':['ME'],'LA':['LA'],'CK':['CK'],'KY':['KY'],'GA':['GA'],'SA':['SA'],'VN':['VN'],'PH':['PH'],'KR':['KR'],'JP':['JP'],'VU':['VU'],'NZ':['NZ'],'TN':['TN'],'IE':['IE'],'SI':['SI'],'SR':['SR'],'FI':['FI'],'AW':['AW'],'NP':['NP'],'FO':['FO'],'SD':['SD'],'ID':['ID'],'CN':['CN'],'MV':['MV'],'UZ':['UZ'],'HK':['HK'],'DZ':['DZ'],'DE':['DE'],'OM':['OM'],'FR':['FR'],'SK':['SK'],'PL':['PL'],'BS':['BS'],'GP':['GP'],'CO':['CO'],'BO':['BO'],'UA':['UA'],'AN':['AN'],'TO':['TO'],'GE':['GE'],'ET':['ET'],'BM':['BM'],'CY':['CY'],'GM':['GM'],'MA':['MA'],'HU':['HU'],'HN':['HN'],'PE':['PE'],'RO':['RO'],'AM':['AM'],'NC':['NC'],'ZM':['ZM'],'IN':['IN'],'TZ':['TZ'],'NL':['NL'],'BE':['BE'],'TR':['TR'],'NA':['NA'],'GD':['GD'],'QA':['QA'],'IS':['IS'],'BH':['BH'],'ZW':['ZW'],'GI':['GI'],'CM':['CM']
    });
});

 //]]>
</script>

then i have two selects which are constructed with php from database tables

<select id="country" name="country">
 <option value="">---------</option>
 <option value="LK">Sri Lanka</option>
 <option value="SY">Syria</option>
 <option value="KE">Kenya</option>
 <option value="KH">Cambodia</option>
 <option value="MN">Mongolia</option>     
 <option value="SN">Senegal</option>
 <option value="PY">Paraguay</option>
 <option value="SE">Sweden</option>
</select>

<select id="city" name="city">
  <option value="3439389">Asuncion</option>
  <option value="3439352">Bella Vista</option>
  <option value="3439101">Ciudad Del Este</option>
  <option value="3438735">Encarnacion</option>
</select>

basically this is all passed with get across the pages this is what the query looks like:

&country=PY  &city=3439101

what i need to do is create another variable called citycode and give the city number to that and use the displayed text as the city value so it would look like this

&country=PY &city=Ciudad Del Este  &citycode=3439101

but how can i create the field &citycode and assign the html option text as a value to the city variable?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:29:39+00:00Added an answer on June 10, 2026 at 3:29 pm
    $('#country option:selected').val(); // returns LK
    $('#country option:selected').text(); // returns Sri Lanka
    
    $('#city option:selected').val(); // returns 3439389
    $('#city option:selected').text(); // returns Asuncion
    

    With this knowledge you can add hidden input to POST/GET request

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title implies I am trying to get an understanding of why in
As the title implies, I need to fetch data from certain website which need
As the title implies, I am using AFNetworking in an iOS project in which
As the post title implies, I have a legacy database (not sure if that
Title pretty much describes it, I just need to get all the order numbers
Just as the title implies, I am trying to create a parser and trying
I really would like to get into HTML 5 way. As a title implies,
Title pretty much says it all. I have a page called login.jsp: <f:view> <html>
As the title implies I'm trying to generate Facebook Open Graph meta tags dynamically,
As the title implies, is there any way I could do this? I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.