【问题标题】:how to to get selected value from drop down in JSP Page with has use for each and need to get id and the selected value from ddl?如何从 JSP 页面中的下拉列表中获取选定的值,每个都有使用,并且需要从 ddl 获取 id 和选定的值?
【发布时间】:2013-11-01 07:37:57
【问题描述】:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">


<title>CompanyProfile</title>

</head>
<body>
<form id="Admin" action="AdminViewServlet" method="post">
<div id="users-contain" class="ui-widget">
<table id="Profile">
<thead>
<tr>
<th style="COLOR: #ffffff; background-color: #910029;">CompanyID</th>
<th style="COLOR: #ffffff; background-color: #910029;">ChangeStatus</th>
</tr>
</thead>
<tbody>
<c:forEach var="Profile" items="${requestScope.allProfile}" varStatus="status">
<tr>
<td>${Profile.companyId}</td>
<td><select id="statuschange" name="statuschange">
<option id="statuschangetype" value="">---Choose a type---
<option id ="statuschangetype1" value="Activate"> Activate
<option id ="statuschangetype2" value=" Deactivate">Deactivate</select></td>
<td  onclick="StatusChange(this)">
<input type="button"  id=${Profile.companyId } value="Change Status"></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</form>
</body>
function StatusChange(click) {
     alert("change status");
     var tablerow = click.parentNode;
     alert("ha ha parentnode...");
     var companyId = tablerow.cells[1].innerHTML;
     alert("id...."+companyId);
     var i = document.getElementById("statuschange");
     var changestatus = i.options[i.selectedIndex].value;
alert("got status" + changestatus);
$.ajax({
type: "GET",
async: false,
dataType: "text",
url: "/Projectlogin/AdminViewServlet",
data: {ActionType:"5",companyId:companyId,status:changestatus},
success: function(TokenData){
alert("testing");
alert("response data: "+TokenData);
   if(TokenData !== null){
alert('Saved !');

returnValue = TokenData;

            }   
        }           

    }); 
}

 </script>
 </html>

嗨,我是一名新程序员,我不确定如何从行中获取选定的下拉值并使用 companyId 更新它。根据上面的代码,我只能得到一次。如果我想在下一行进行更改,它会给我之前更改的值。
请帮助我了解如何从每一行进行状态更新。

问候, 红宝石

【问题讨论】:

  • 谢谢亚格内什。我试过了,但它没有给我任何价值。问候,鲁比

标签: javascript jsp-tags


【解决方案1】:

因为在行

var i = document.getElementById("statuschange");  

它总是选择第一行下拉列表,因为所有下拉列表都有相同的 ID。
将下拉 ID 作为 companyId 并在上面的代码中替换该 ID,您将获得每一行的正确值。

您可以为所有下拉列表指定 id,以便所有下拉列表获得不同的 id。

我认为他会帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多