-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path셀렉트박스 선택하면 라디오,텍스트필드에 값전달하기.jsp
More file actions
184 lines (149 loc) · 4.74 KB
/
셀렉트박스 선택하면 라디오,텍스트필드에 값전달하기.jsp
File metadata and controls
184 lines (149 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>스탭관리</title>
</head>
<body>
<table style='border:1px solid green'>
<tr>
<td style='border:1px solid green'>
<select id=selStaff size=20 style='width:300px'><table id="tt2"><tr><td></td><td></td><td></td></tr></table></select>
</td>
<td style='border:1px solid green' valign=top>
<table>
<tr height=40px>
<td>이름: <input type=text name ="txtnick"id=txtnick size=30></td>
</tr>
<tr height=40px>
<td>모바일: <input type=text name="txtmobile" id=txtmobile size=20></td>
</tr>
<tr height=40px>
<td>성별: <input type=radio value='f' id=female name=gender>여성
<input type=radio value='m' id=male name=gender>남성
</tr>
<tr height=40px>
<td><input type=button id=btnInsert value='등록'>
<input type=button id=btnDelete value='삭제'>
<input type=button id=btnReset value='비우기'>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script>
var ar =[];
$(document).ready(function() {
var item ;
$.get('selectAll',{},function(data){
//json방식//
ar = data;
console.log(data);
console.log(ar);
$.each(data,function(ndx,value){
//서블릿에서 써준대로 값을 써준다.//
//name='<option><tr><td>'+value['NICK']+'</td><td>'+value['MOBILE']+'</td><td>'+value['GENDER']+'</td></tr></option>';
name='<option>'+value['NICK']+','+value['MOBILE']+','+value['GENDER']+'</option>';
$('#selStaff').append(name);
//$('#tt2').append(name);
console.log('btnGet3')
})
},'json');//===>2개이상 타입 은 json 이라한다.//text는 하나//
return false;
});
var nClick=null;
var radioVal = $('input[name="gender"]:checked').val();
$(document)
.on('click','#btnInsert',function(){
//===>insert<===//
var r2 ;
var r3 ;
alert(radioVal)
$.ajax({
url:'insert1',//호출될 서블릿의 경로(이름)
method:'get',//데이터 전송방식 get/post
beforeSend:function(){
/*
if($('input[name="gender"]:checked').val()=="female"){
r2 = $('input[name="gender"]:checked').val('f')
}
// $("input[type=radio][name=gender]").val('f');
if($('input[name="gender"]:checked').val()=="male"){
$('input[name="gender"]:checked').val('m')
//$("input[type=radio][name=gender]").val('m');
}
*/
console.log(r2)
},
data:'txtnick='+$('input[name=txtnick]').val()+'&txtmobile='+$('input[name=txtmobile]').val()+'&gender='+$('input[name="gender"]:checked').val(),
dataType:'text',//반환받을 데이터 타입
success:function(txt){//호출 성공해서 완료하면
alert("입력완료되었습니다.");
},
complete:function(){
alert("hi");
}
})
window.location.reload(true)
})
$(document)
.on('click','#btnDelete',function(){
$.ajax({
url:'delete1',//호출될 서블릿의 경로(이름)
method:'get',//데이터 전송방식 get/post
data:'txtnick='+$('input[name=txtnick]').val(),
dataType:'text',//반환받을 데이터 타입
beforeSend:function(){},
success:function(txt){//호출 성공해서 완료하면
alert("입력완료되었습니다.");
},
complete:function(){
alert("hi");
}
})
window.location.reload(true)
})
$(document)
.on('click','#selStaff',function(){
//var idx = $("#selStaff option:selected").index();
//console.log(idx)
txt=$(this).text();
console.log(txt)
id=$(this).find('option:selected').text();
console.log(id)
ar = id.split(',');
//alert(id);
//$("#txtnick").val(id);
console.log(ar)
console.log(ar)
$("#txtnick").val(ar[0])
$("#txtmobile").val(ar[1])
if(ar[2]=="f"){
var v9= $("input:radio[name='gender']:radio[value='f']").prop("checked",true);
}
if(ar[2]=="m"){
var v9= $("input:radio[name='gender']:radio[value='m']").prop("checked",true);
}
/*
if($('input[name="gender"]:checked').val()=="f"){
var v9= $("input:radio[name='gender']:radio[value='f']").prop("checked",true);
}
*/
if($('input[name="gender"]:checked').val()=="m"){
$("input:radio[name='gender']:radio[value='m']").prop("checked",true);
}
//v20= $("#selStaff option:eq(1)").val();
})
$(document)
.on('click','#btnReset',function(){
$("#txtnick").val("");
$("#txtmobile").val("");
$("#txtnick").val("");
$("input:radio[name='gender']").prop("checked", false);
})
</script>