简体   繁体   中英

Javascript: How to open a form with fields filled with parameters?

I'd like to open a form with its fields filled with data corresponding to a certain record.

Example:

  • Supose a certain form:

    Dogs

      <table id="tabledogs" class="ui-widget ui-widget-content"> <thead> <tr class="ui-widget-header "> <th>ID</th> <th>Name</th> <th>Action</th> </tr> </thead> <tbody> <c:forEach var="dog" items="${sessionScope.dogs}"> <tr> <td width="50%" align="left">${dog.id}</td> <td width="50%" align="left">${dog.name </td> <td><button id="update">Update</button> </td> </tr> </c:forEach> </tbody> </table> </div> 
  • I'd like to open the following form with the corresponding dog data within it (there's other form configurations not showed here for space-saving):

      <form> <fieldset> <label for="id">ID</label> <input type="text" name="id" id="id" class="text ui-widget-content ui-corner-all" /> <label for="name">Name</label> <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" /> </fieldset> </form> </div> 

For while I have the following JavaScript, wich opens the form but without data:

$("#update").button().click(function() {
    $("#dialog-form").dialog("open");
});
  • All this stuff are working properly. How can I pass dog's data to the form to be shown? As you probably saw, I have a set of "dog" objects in SessionScope. Thanks for helping!!

jQuery有一个.val()函数,可以执行您想要的操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM