input 자동 추가방법 질문입니다

input 자동 추가방법 질문입니다

QA

input 자동 추가방법 질문입니다

답변 1

본문

늘 고수님들의 도움을 받고 있습니다. 감사합니다.

 

iput추가 삭제관련 자바 소스가 있던데...잘 되더군요,,,

그런데 추가되는 input id, name, value를 wr_1~~wr_70.... 즉wr_x이런 식으로 정해줘야 db에 저장이 될 거 같은데 이런경우 어떻게 고쳐야 할지 가르쳐주시면 감사하겠습니다.

 

<html>

 

<head>

 

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>

 

<script>

 

$(document).ready(function() {

 

var id = 0;

 

 

// Add button functionality

 

$("table.dynatable button.add").click(function() {

 

id++;

 

var master = $(this).parents("table.dynatable");

 

 

// Get a new row based on the prototype row

 

var prot = master.find(".prototype").clone();

 

prot.attr("class", "")

 

prot.find(".id").attr("value", id);

 

 

master.find("tbody").append(prot);

 

});

 

 

// Remove button functionality

 

$("table.dynatable button.remove").live("click", function() {

 

$(this).parents("tr").remove();

 

 

});

 

});

 

</script>

 

<style>

 

.dynatable {

 

border: solid 1px #000; 

 

border-collapse: collapse;

 

}

 

.dynatable th,

 

.dynatable td {

 

border: solid 1px #000; 

 

padding: 2px 10px;

 

width: 170px;

 

text-align: center;

 

}

 

.dynatable .prototype {

 

display:none;

 

}

 

</style>

 

</head>

 

<body>

 

<table class="dynatable">

 

<thead>

 

<tr>

 

<th>ID</th>

 

<th>Name</th>

 

<th>Col 3</th>

 

<th>Col 4</th>

<th>Col 5</th>

<th>Col 6</th>

<th>Col 7</th>

<th><button class="add">추가</button></th>

 

</tr>

 

</thead>

 

<tbody>

 

<tr class="prototype">

 

<td><input type="text" name="id" value="0" class="id" /></td>

 

<td><input type="text" name="name" value="" /></td>

 

<td><input type="text" name="col1" value="" /></td>

 

<td><input type="text" name="col2" value="" /></td>

<td><input type="text" name="col3" value="" /></td>

<td><input type="text" name="col4" value="" /></td>

<td><input type="text" name="col5" value="" /></td>

 

<td><button class="remove">X</button>

 

</tr>

 

</table>

 

</body>

 

</html>

 

 

이 질문에 댓글 쓰기 :

답변 1

name  = "wr_"+id;
var master = $(this).parents("table.dynatable");
// Get a new row based on the prototype row
var prot = master.find(".prototype").clone();
prot.attr("class", "");
prot.find('input').attr('name',name)
prot.find(".id").attr("value", id);

답변 감사드립니다~
추가시키는 인풋모두 name, value에  wr_0으로 일단 표시되는군요,,,
이렇게 되면 필드명이 중복되어 저장이 안될거 같아서요,,
 
wr_11~ 115까지 순차적으로 메기고자 하는데 이경우 어떻게 해줘야 할지요,,
즉 15행까지만 추가가능하게 하려고 합니다.
 
소스에는 무지해서 방법을 모르겠네요.. 혹시 알려주시면 감사하겠습니다.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 125,873
© SIRSOFT
현재 페이지 제일 처음으로