JavascriptとJava各種formフォーム情報の取得


          form       input  。       input         Document.getElementById          。      form   checkbox  radio  select     javascript                  ?    、   :
Jsp-html  :
	<form action="input.do" name="formkk">
			<table>
				<tbody>
					<tr>
						
						<td>text:</td>
						<td>
							<input type="text" name="text">
						</td>
					</tr>
					<tr>
						
						<td>password:</td>
						<td>
							<input type="password" name="pass">
						</td>
					</tr>
					<tr>
						
						<td>radio:</td>
						<td>
							<input type="radio" name="xingbie" value="1">
							 
							<input type="radio" name="xingbie" value="2">
							 
						</td>
					</tr>
					<tr>
						<td>checkbox:</td>
						<td>
							  :<input type="checkbox" name="hobby" value="1"  />
							  :<input type="checkbox" name="hobby" value="2"  />
							  :<input type="checkbox" name="hobby" value="3"  />
							  :<input type="checkbox" name="hobby" value="4"  />
						</td>
					</tr>
					<tr>
						<td>hidden:</td>
						<td>
							<input type="hidden" value="123" name="hidden"/>
						</td>
					</tr>
					<tr>
						<td>option:</td>
						<td>
							<select name="opt" id="opt">
							<option>1</option>
							<option>2</option>
							<option>3</option>
							<option>4</option>
							</select>
							
						</td>
				</tbody>
			</table>
			<input type="button" value="  " onclick="javascript:check()"/>
		</form>


Javascript:
function check(){
			
			var radio = document.getElementsByName("xingbie");
			var checkbox = document.getElementsByName("hobby");
			var select = document.getElementById("opt");
		
			//  select  
			var index = select.selectedIndex;
			var text = select.options[index].text;
			var value = select.options[index].value;
			
			//  radio  
			for(var i=0;i<xingbie.length;i++){
				if(xingbie.item(i).checked){
					var val = xingbie.item(i).getAttribute("value");
					break;
				}
				continue;
			}
			//  checkbox  
			for(var i=0;i<hobbys.length;i++){
				if(hobbys[i].checked){
					alert(hobbys[i].value);
				}
				continue;
			}
			
			//  form  
			document.formkk.submit();
			
			
		}



Java:
	String[] hobbys = request.getParameterValues("hobby");  //checkbox
	String text = request.getParameter("text");				//text
	String password = request.getParameter("password");	//password
	String xingbie = request.getParameter("xingbie");		//radio
	request.getParameter("hidden");
	request.getParameter("opt");    //select