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 7664509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:19:28+00:00 2026-05-31T14:19:28+00:00

First off sorry for a re-post, I voted to delete my old post because

  • 0

First off sorry for a re-post, I voted to delete my old post because I’m asking for help on the code now, not just which way is the better route. Any my code has changed several times

On my page there is a drop down to select a country, dynamically loaded from a db. Once the user selects a country two things can happen. 1) If they select Canada or the US a second drop-down appears and the user can select a region. 2) If the user selects any other country it creates an input box so that the user can type the region instead. This all works fine.

Now there is a third input which takes the province/state value so it can be posted. There are only two of us who will use this form so I’m not worried about JavaScript being turned off in the browser.

My issue is that when the user first selects the Canada/US and a region, nothing is filled into the third input unless they change the country selection. However, if they select a country other than Canada/US and have to type the region, it works as expected.

Here is an example of the issue: http://jsfiddle.net/owalsh/BQXZA/3/

If anyone can tell me why I’d appreciate it, 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-05-31T14:19:30+00:00Added an answer on May 31, 2026 at 2:19 pm

    Working here: http://jsfiddle.net/5A4v4/11/

    HTML:

    <form id="customer_bill_add_post" name="customer_bill_add_post">
    <select id="country" name="country">
        <option value="0">Select a country</option>
        <option value="CA">Canada</option>
        <option value="US">United States</option>
        <option value="OT">Other</option>
    
    </select>
    
    <select id="province_select" name="province_select">
        <option value="0">Select a Province</option>
        <option value="AB">Alberta</option>
        <option value="AL">Alabama</option>
    </select>
    
    <input type="text" id="province_input" name="province_input">
    <input type="text" id="province" name="province" />
        </form>
    

    Jquery: code (there was some extra change event binding going on) you can prettify it.

            $(function(){
                //initially hide the textbox
                $("#province_input").hide();
                $("#province_select").hide();
    
                $('#country').change(function() {
                    if($(this).find('option:selected').val() == "CA"){
                     $("#province_select").show();
                     $("#province_input").hide();
                     } else if($(this).find('option:selected').val() == "US"){
                     $("#province_select").show();
                     $("#province_input").hide();
                     } else {
                     $("#province_input").show();
                     $("#province_select").hide();
                    }
                 });
    
    
    $('#country, #province_select, #province_input').bind("change", function() {
        if($('#country').find('option:selected').val() == "CA"){  
        document.customer_bill_add_post.province.value = document.customer_bill_add_post.province_select.value;
        } else if($('#country').find('option:selected').val() == "US"){
            document.customer_bill_add_post.province.value = document.customer_bill_add_post.province_select.value;
        } else {
            //alert('foo');
            document.customer_bill_add_post.province.value = document.customer_bill_add_post.province_input.value;
            }
    });        
    
    
    });
    

    Cheers,

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

Sidebar

Related Questions

First off - sorry for the wall of code but it's not too horrendous,
First off, sorry about the long post. Figured it's better to give context to
First off sorry if I'm missing something simple just started working with AJAX today.
First off, sorry for what I know is terrible idiomatic Ruby code. I am
First off, let me start off that I am not a .net developer. The
First off, this question is ripped out from this question. I did it because
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
First off, sorry for the lame title, but I couldn't think of a better
First off, sorry if the title is confusing! I'm working on a part of
first of all sorry for the title. I know this is not so clear

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.