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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:44:03+00:00 2026-05-21T04:44:03+00:00

A] Summary of the problem: Trying to pre-select a users country on page load

  • 0

A] Summary of the problem:

Trying to pre-select a users country on page load

B] Details:

1] I am using maximinds javascript to find out a users county.

2] I have a drop down list which contains a list of 225 or so countries.

3] Inside the javascript section of my HTMLr page, I am trying to select the users country from the drop-down list.

But the country is not getting selected

C] Code excerpt:

<select name="country_name" id="id_country_name">
 <option value="" selected="selected">---------</option>
 <option value="Afghanistan">Afghanistan</option>
 <option value="Aring land Islands">Aring land Islands</option>
</select>


<!-- including the  geoip javascript library -->
<script src="http://j.maxmind.com/app/geoip.js" type="text/javascript"></script>
<!-- By default, we will select users country -->       
<script type="text/javascript" language="JavaScript">
document.getElementById(geoip_country_name()).selected = true
</script>

Thanks,

[Edit#1]

Tried the following jquery code, but this isnt populating the drop-down list:

<!-- including the  geoip javascript library -->
  <script src="http://j.maxmind.com/app/geoip.js" type="text/javascript"></script>
  <script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript">
    $(function () {
        $("option[value='" + geoip_country_name() + "']").attr('selected', 'selected');
    });
 </script>

[Edit#2]

Tried the $(“#id_country_name”).val(geoip_country_name());,

<div id="userDataForm">
  <form method="POST" action="/UserReporting"> 
  <table>
      <!-- Printing the forms for users country, city -->
      <tr><th><label for="id_country_name">Country name:</label></th><td>
      <select name="country_name" id="id_country_name">
    <option value="" selected="selected">---------</option>
    <option value="Afghanistan">Afghanistan</option>
        <option value="Aring land Islands">Aring land Islands</option>
        <option value="Albania">Albania</option>
      </select>
      </td></tr>
      <tr><th>
      <label for="id_city_name">City name:</label></th><td><input type="text" name="city_name" id="id_city_name" /></td></tr>     
 </table>

 <input type="submit" name="report_up" value= "Report Up">
 <input type="submit" name="report_down" value= "Report Down">
 </form>

 <!-- including the  geoip javascript library -->
<script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script src="http://j.maxmind.com/app/geoip.js" type="text/javascript">
</script>
<script type="text/javascript">
    $(function () {
        $("#id_country_name").val(geoip_country_name());
    });
</script>
  • 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-21T04:44:04+00:00Added an answer on May 21, 2026 at 4:44 am

    The document.getElementById call would only work if each <option> in your HTML had the country name as the id (replacing spaces with “_” or something similar):

    <select name="country_name" id="id_country_name">
     <option value="" selected="selected">---------</option>
     <option id="Afghanistan" value="Afghanistan">Afghanistan</option>
     <option id="Aring_land_Islands" value="Aring land Islands">Aring land Islands</option>
    </select>
    

    However, I’d lean towards this approach with jquery, as it doesn’t require giving every option its own id:

    $(function () {
        $("#id_country_name").val(geoip_country_name());
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SUMMARY: When browsing an ASP.NET website using Windows Explorer, popup windows do not borrow
Summary: I'm able to compile a RAD Studio 2009 project using MSBuild on a
I need to have a summary field in each page of the report and
What references offer a good summary/tutorial for using RDF/OWL? There seem to be enough
Summary Hi All, OK, further into my adventures with custom controls... In summary, here
Summary What's the best way to ensure a table cell cannot be less than
Summary: I'm developing a persistent Java web application, and I need to make sure
Summary: Can I program a thick client game in C without reinventing wheels ,
Executive Summary: When assertion errors are thrown in the threads, the unit test doesn't
Is there an easy way to get a conflict summary after running a cvs

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.