:::: 개발 ::::/└ JSP & SPRING

jsp selectbox 선택

nayha 2013. 11. 25. 20:43

위의 예제 응용입니다 
<option value='t001' <%=topographyValue.equals("t001") ? "selected" : "" %> >어쩌구</option> 
혹은 
------------------------------------------------------- 
function setComboValue(obj, str){ 
var otype; //OBJECT TYPE 
if (obj == null) return ; 
if (chk_Blank(str)) return ; 
otype = (obj.type).substring(0,6); 

if (otype != "select") return ; 

for (var index = 0; index < obj.length; index++) { 
if (obj.options[index].value != '') { 
if (trim(obj.options[index].value) == trim(str)) { 
obj.options[index].selected = true; 

} else { 
if (trim(obj.options[index].text) == trim(str)) { 
obj.options[index].selected = true; 





공통 자바스크립트 펑션에 요너마 만들어 놓고 

<body onload="init()"> //body에 init() javascript호출후 

자바스크립트 정의하는곳에 요너마 낑겨 넣으삼 

function init(){ 
f = document.writeForm; //writeForm은 select박스를 둘러싼 form name 
setComboValue(f.topography, "<%=topographyValue%>"); 
}


okjsp 펌


실제 적용 부분...


<form id="form" name="form" method="post" enctype="multipart/form-data">


$(document).ready(function() {

init();

});

function init(){ 

setComboValue(form.bond_type, "<%=bond_type%>");

setComboValue(form.term, "<%=bond_term%>");

//셀렉트 박스 disabled

document.all['bond_type'].disabled = true;

document.all['term'].disabled = true;

}

function setComboValue(obj, str){ 

var otype; //OBJECT TYPE 

if (obj == null) return ; 

//if (chk_Blank(str)) return ; 

otype = (obj.type).substring(0,6); 

if (otype != "select") return ; 


for (var index = 0; index < obj.length; index++) { 

if (obj.options[index].value != '') { 

if (obj.options[index].value == str) { 

obj.options[index].selected = true;


} else { 

if (obj.options[index].text == str) { 

obj.options[index].selected = true; 

}



반응형