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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:50:52+00:00 2026-05-17T20:50:52+00:00

I have a piece of code that is working fine in IE, but it

  • 0

I have a piece of code that is working fine in IE, but it doesn’t run in Firefox. I think the problem is that I have not been able to implement $('document').ready(function). The structure of my json is like [{“options”:”smart_exp”},{“options”:”user_intf”},{“options”:”blahblah”}].
I will be very thankful if someone can see my code & help me in correctly implementing it. Here is my code:

<html><head>
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2
     /jquery.min.js"></script>
     <script type="text/javascript" language="javascript">
     $(document).ready(function() { 
     $.getJSON("http://127.0.0.1/conn_mysql.php", function (jsonData) {
     $.each(jsonData, function (i, j) {
     document.form1.fruits.options[i] = new Option(j.options);
     });});
     });
     </script></head>
     <body><form name="form1">
     My favourite fruit is :
     <select name="fruits" id="fruits" /></form></body>
</html>
  • 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-17T20:50:52+00:00Added an answer on May 17, 2026 at 8:50 pm

    Just run $(document).ready(function() {doStuff}). This will automatically run when the document is ready.

    It’s best practice, at least in my opinion, that you don’t put any events in the html itself. This way you separate the structure of an html document from it’s behavior. Instead attach events in the $(document).ready function.

    <html>
      <head>
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
         <script type="text/javascript">
           $(document).ready(function() { 
               $.getJSON("http://localhost/conn_mysql.php", function (jsonData) {
                 var selectElem = $('#fruits');
    
                 for(var i = 0; i < jsonData.length; i++) { 
                   selectElem.append($('<option>').html(jsonData[i].options));
                 }
    
               });
           });
         </script>
      </head>
      <body>
        <form name="form1">
          My favourite fruit is :
          <select name="fruits" id="fruits" />
        </form>
      </body>
    </html>
    

    EDIT:
    I tested with the following and mocked the json object since I can’t make that call myself.

    <html>
      <head>
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
         <script type="text/javascript">
           $(document).ready(function() {
               var jsonData = JSON.parse('[{"options":"smart_exp"},{"options":"user_intf"},{"options":"blahblah"}]');
               var selectElem = $('#fruits');
    
               for(var i = 0; i < jsonData.length; i++) { 
                 selectElem.append($('<option>').html(jsonData[i].options));
               }
    
           });
         </script>
      </head>
      <body>
        <form name="form1">
          My favourite fruit is :
          <select name="fruits" id="fruits" />
        </form>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code that is working fine in python 2.7. dist
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated
I have this piece of code for MFMailComposer working fine in the simulator and
Currently I have a piece of code that works fine as long as there
To put the problem simply, I have a piece of code that is currently
I currently have a piece of code that I am working on using function
Problem in brief I have got a piece of working two dimensional scrolling code.
I still need your help. I have this piece of code that doesn't want
I have a piece of code that needs to run inside a Swing application

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.