使用javascript从表单获取记录值

时间:2015-05-06 05:45:43

标签: java javascript html css jsp

我想从下表中获取id和name的值,并发送到服务器以更新记录。 到目前为止,我已经使特定记录可编辑,但我完全无法获得服务器端的更新值。我是JavaScript的新手。感谢帮助。

JavaScript代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="/struts-tags" prefix="s" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Records</title>
<link rel="stylesheet" type="text/css" href="/XMLTest/css/tableStyle.css" />
<script type="text/javascript">
function makeEditable(elem) {

    var parentNode =  elem.parentNode.parentNode;
    var childs = parentNode.childNodes;

    for(var i = 0; i < childs.length-1; i++){
        var innerChilds = childs[i].childNodes;
        var innerChildValue = "";

        if( innerChilds.length > 0){
            for(var j = 0; j < innerChilds.length; j++){
                var tag = innerChilds[j];

                if(tag.type == 'button')
                    continue;

                if(tag.type == 'hidden')
                    innerChildValue = tag.value;
            }
        }

        childs[i].innerHTML = "<input type='text' size='10' value='" +innerChildValue +"' />";
    }

    childs[childs.length-1].innerHTML = "<form action='updateOrganization'><input type='hidden' name='id' value='' /><input type='submit' value='Save'/></form><input type='button' value='Cancel' onClick='window.location.reload()'/>";
}
</script>
</head>
<body>

<jsp:include page="/header.jsp"></jsp:include>
<center>
<display:table id="record" name="listOfOrganization" requestURI="/organization" pagesize="10">
    <display:caption>Organization Records</display:caption>

    <display:column title="Id">
    <c:out value="${record.id}"></c:out>
        <input type="hidden" name="id" value="${record.id}" />
    </display:column>

    <display:column title="Name" >
        <c:out value="${record.name}"></c:out>
        <input type="hidden" name="name" value="${record.name}" />
    </display:column>

    <display:column media="html">
        <input type="button" onclick="makeEditable(this)" value="update" />
        <input type="button" onclick="makeEditable(this)" value="view" />
    </display:column>
</display:table>

</body>
</html>

0 个答案:

没有答案