【问题标题】:Trouble Creating Forms in AJAX/Javascript/HTML based upon drop down selection根据下拉选择在 AJAX/Javascript/HTML 中创建表单时遇到问题
【发布时间】:2013-01-09 17:12:48
【问题描述】:

我的工作需要一个非常简单的 Web 表单,我们将使用它来提交内部工作。作品提交将分为 4 个类别,每个类别都需要独特的信息。现在我有一个简单的表单,它执行以下操作:

请求的名称:[文本框]
请求日期:[文本框]
获取:[文本框]
请求类型:[下拉] 4 项

我想要的是取决于选择的下拉项目,用户应该会看到下面显示的正确表单。其中将包含一个表格形式更多“输入的项目和文本框”。

现在我正在尝试这个,但我遇到了多个问题,即我只能看到一个表格行,而不是选择的所有内容。

所以也许我以错误的方式解决问题?所以我要投身于你面前,谦卑地寻求帮助。要么是正确方向的点,要么是此时的任何东西!

$(document).ready(function() {
   $('select[name="select_main_table"]').change(function() {
      $("#main_table tr").hide().eq(this.value-1).show();
   }).change();
});



      <td><label for="typeofrequest">Type of Request</label></td>
      <td><select name="select_main_table">
        <option value="" selected="selected"> - Choose -</option>
        <option value="1">Office Move</option>
        <option value="2">Office Closure</option>
        <option value="3">New Office</option>
        <option value="4">New Service</option>
      </select>          </td>
      <td>&nbsp;</td>
    </tr>

   <table id="main_table">
    <tr> 
      <td><label for="sitecontactname">Site Contact Name</label></td>
      <td><input type="text" class="validate[required,custom[sitecontactname]]" name="sitecontactname" id="sitecontactname" value="" /></td>
      <td>&nbsp;</td>
    </tr>

    <tr>  
      <td><label for="sitecontacttitle">Site Contact Title</label></td>
      <td><input type="text" class="validate[required,custom[sitecontacttitle]]" name="sitecontacttitle" id="sitecontacttitle" value="" /></td>
      <td>&nbsp;</td>
    </tr>

    <tr> 
      <td><label for="sitecontactemail">Site Contact Email</label></td>
      <td><input type="text" class="validate[required,custom[sitecontactemail]]" name="sitecontactemail" id="sitecontactemail" value="" /></td>
      <td>&nbsp;</td>
    </tr>

    <tr>  
      <td><label for="sitecontacttelephonenumber">Site Contact Telephone Number</label></td>
      <td><input type="text" class="validate[required,custom[sitecontacttelephonenumber]]" name="sitecontacttelephonenumber" id="sitecontacttelephonenumber" value="" /></td>
      <td>&nbsp;</td>
    </tr>
   </table>

【问题讨论】:

  • 为什么你的代码中间会出现表格的一部分?
  • @TomJones:欢迎来到 StackOverflow。我删除了你是谁的介绍。如果您认为这是有用的信息,您可以从历史记录中检索它并将其添加到您的个人资料页面。
  • Keeg - 函数下方的所有内容都是我从项目中删除的一段代码。我试图保持简短,所以我提出了我认为是问题的内容。

标签: javascript jquery html css ajax


【解决方案1】:

感谢您的帮助。我能够在另一个网站上找到一些代码,这些代码让我找到了更好的解决方案。

【讨论】:

    猜你喜欢
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    相关资源
    最近更新 更多