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

The Archive Base Latest Questions

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

I have an HTML form that builds a drop-down from json data that is

  • 0

I have an HTML form that builds a drop-down from json data that is retrieved dynamically on page load from a php script.

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() { 
        jQuery .getJSON("http://127.0.0.1/conn_mysql.php", function (jsonData) {
        $.each(jsonData, function (i, j) {
        document.index.user_spec.options[i] = new Option(j.options);
     });});
     });
</script></head>
<body>
<form name="index">
<select name="user_spec" id="user_spec" />
</form>
</body>
</html> 

The php script fetches data from a MySQL table.

<?php  
      $username = "user";  
      $password = "********";  
      $hostname = "localhost";  
      $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect   
      to MySQL");  
      $selected = mysql_select_db("spec",$dbh) or die("Could not select first_test");  $query =
      "SELECT * FROM user_spec";  
      $result=mysql_query($query);     
      $outArray = array(); 
      if ($result) { 
      while ($row = mysql_fetch_assoc($result)) $outArray[] = $row; 
    } 
      echo json_encode($outArray);  
?> 

I need to add functionality to it now that new options can be added dynamically from the form to the list. How can I do it? I am thinking to do it like user adds an option to a text box & presses a button. The same JSON data is modified & posted back to server that reads & stores it into database. The list is refreshed/re-drawn with this changed data.

  • 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:31:49+00:00Added an answer on May 17, 2026 at 8:31 pm
     jQuery .getJSON("http://127.0.0.1/conn_mysql.php", function (jsonData) {
    
        $("#user_spec").html("");//clear old options
                    jsonData= eval(jsonData);//get json array
    
                    for (i = 0; i < jsonData.length; i++)//iterate over all options
                    {
                      for ( key in jsonData[i] )//get key => value
                      { 
                            $("#user_spec").get(0).add(new Option(jsonData[i][key],[key]), document.all ? i : null);
                      }
                    }
    
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form on an HTML page with multiple submit buttons that perform
I have an HTML form - with PHP, I am sending the data of
I have a basic HTML form that gets inserted into a server side div
I have a HTML form, and I have a Controller Action that accepts the
I have a site that has a simple HTML button in a form. All
There are some HTML based games (ie bootleggers.us) that have a simple login form
I have an HTML order form that collects info and then on submission passes
I have a legacy HTML form that I want to make into a Spring
I have a _form.html.erb partial that comes from the standard rails 3 template for
If I have a HTML form with some embedded div s, and after the

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.