2012-07-18 4 views
0

3 개의 텍스트 상자와 1 개의 텍스트 영역이 있습니다. 아이디, 이름, 주소, 연락처. 모두 빈 필드를 검사 할 목적으로 스크립팅 된 Java 스크립트입니다. 나는이 방법으로 그것을했다 :텍스트 영역의 빈 필드 확인

자바 스크립트 코드 :

function checkForm()  
{ 
var id=document.getElementById("id").value; 
var name=document.getElementById("name").value; 
var address=document.getElementById("address").value; 
var contact=document.getElementById("contact").value; 


if(id.length<1)   
{ 
alert("Please enter all the informations!"); 
return false; 
} 
if(name.length<1)  
{ 
alert("Please enter the name!"); 
return false; 
} 
if(address.length<1)  
{ 
alert("Please enter the address!"); 
return false; 
} 
if(contact.length<1)  
{ 
alert("Please enter the contact!"); 
return false; 
} 

HTML 코드 : 모든 텍스트 영역을 제외하고 노력하고 있습니다

<form method="post" action="clients.php" onSubmit="return checkForm()"> 
    id <input type="text" name="id" id="id"> 
    name <input type="text" name="name" id="name"> 
    address <textarea name="address" id="address"> </textarea> 
    contact <input type="text" name="contact" id="contact"> 
    <input type="submit" name="submit" value="Enter"> 
</form> 

. 인터넷에 설립 된 다른 코드로 시도하고 있지만 작동하지 않습니다. 일련 번호 유지 (ID를 누른 다음 주소를 다음 연락처 ....) 어떻게 텍스트 영역의 빈 공간을 확인할 수 있습니까?

미리 감사드립니다.

답변

1

사용 트림 기능이 공백

var id=document.getElementById("id").value.trim(); 
var name=document.getElementById("name").value.trim(); 
var address=document.getElementById("address").value.trim(); 
var contact=document.getElementById("contact").value.trim(); 
+0

죄송합니다을 제거하기 위해, 그것은 작동하지 않습니다. "innnerHTML"을 사용하여 자바 스크립트는 첫 번째 두 항목 만 확인합니다. @Ankit –

+0

여 !! !! 그렇습니다. var address = document.getElementById ("address") 만 변경해야합니다. value.trim(); 어쨌든 고맙습니다 ......... 좋은 하루 보내십시오 .... Ankit Gautam :) :) –

+0

누를 때 공백 입력을 막을 수있는 모든 분야에 대해 아니오 스페이스 바 – bugwheels94

관련 문제