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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:50:44+00:00 2026-05-23T08:50:44+00:00

Using jQuery/jQueryUI I want to populate a form using this HTML/JS show below. The

  • 0

Using jQuery/jQueryUI I want to populate a form using this HTML/JS show below.

The url “editController/loadContents” will return some data and .html will (I believe) populate the form based upon the data but what structure should the data have ?.

The only examples I can find in the jQueryUI doco are for single element forms.

My guess is that some JSON which looks like this …

{
     "starttime": "10:00",
     "endtime": "11:00",
 }

… would populate the input fields. But how are the OPTIONS for the SELECTs provided and one of the the OPTIONs specified as ‘selected’ ?

<div id="dialog" title="Basic dialog">
  <!-- loaded from ajax call -->
  <form id="exampleForm">
    <fieldset>
    <label for="activity">Activity</label>
    <br />
    <select name="activity" id="activity" class="ui-widget-content ui-corner-all">
    </select>
    <br />
    <label for="subactivity">Sub-Activity</label>
    <br />
    <select name="subactivity" id="subactivity" class="ui-widget-content ui-corner-all">
    </select>
    <br />
    <label for="activity">Reason</label>
    <br />
    <select name="reason" id="reason" class="ui-widget-content ui-corner-all">
    </select>
    <br />
    <label for="starttime">Start</label>
    <br />
    <input type="text" name="starttime" id="starttime" class="text ui-widget-content ui-corner-all" />
    <br />
    <label for="endtime">End</label>
    <br />
    <input type="text" name="endtime" id="endtime" class="text ui-widget-content ui-corner-all" />
    <br />
    </fieldset>
    <input type="button" onclick="Save()" />
  </form>


</div>

<script>
  $(function() {
      $('.myPop').click(function() {
          $.get("editController/loadContents", function(data){
             $("#dialog").html(data);
           });           
          $("#dialog").dialog('open');
      });
  });


function Save(){
 $.post("/editController/Edit", $("#exampleForm").serialize(),
  function(data){
     $("#dialog").dialog('close');
    //update grid with ajax call
  });
}

</script>

BTW I’ve adapted this code from the very useful answer at How to use a jQuery UI Modal Form from ASP.Net MVC list page

  • 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-23T08:50:45+00:00Added an answer on May 23, 2026 at 8:50 am

    .html will (I believe) populate the
    form based upon the data but what
    structure should the data have ?.

    .html() simply sets the HTML content of the matched elements in your jQuery selector to the contents you provide. There’s no automatic setting of values for existing inputs based on a JSON object.

    This leaves you with two options:

    1. Make your server-side code return a populated HTML form that you blindly use .html() with, or
    2. Write JavaScript to associate the raw data you get back from the server with the inputs that exist on your page.

    But how are the OPTIONS for the
    SELECTs provided and one of the the
    OPTIONs specified as ‘selected’ ?

    To dynamically insert options into an existing select element, you could simply generate a new option element and .append() it:

    $("<option>")
        .text("Swimming")
        .attr("selected", true) // Set the option's "selected" attribute
        .attr("value", 1)
        .appendTo("#activity");
    

    Obviously, you would have to adapt that code to the JSON data you get back from your server-side code, probably looping through an array of activities you got back and creating a new option for each one.

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

Sidebar

Related Questions

I'm using this simple modal dialog example here: http://jqueryui.com/demos/dialog/modal-form.html When the page loads, jQuery
I am building a html menu and I am using jQuery UI to format
I am using this code for this plugin http://unwrongest.com/projects/defaultvalue/ // <![CDATA[ $.noConflict(); jQuery(document).ready(function(){ jQuery('.defaultval').defaultValue();
I'm using jquery ui autocomplete and want to decipher between focus events triggered by
I'm pretty new to jQuery and javaScript programming and wondered if anyone could help
I have a basic username textbox. This textbox can be seen here: http://68.71.136.106/test.htm In
I have the following page layout using the 960 grid systm ---------------- header -----------------
I am trying to implement a JqueryUI button called favorites (id=#favorites) for thumbnails in
I have a ViewModel setup to use RemoteValidation using the RemoteAttribute . It works
I have a simple web application in which I have created a wizard, each

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.