2 개의 텍스트 필드와 하나의 파일 필드가있는 양식을 만들었습니다. 'text'
필드 에 Javascript를 추가했습니다 . 사용자가 'text'
필드를 떠나서 제출 버튼을 누르면 All Fields are Required
글꼴이 빨간색으로 바뀌고 사용자가 이미지를 업로드하지 않았을 때도 빨간색으로 바꾸고 싶습니다. 나는 다양한 방법을 시도했지만 작동하지 않습니다. 방법을 알려주세요.
<script type="text/javascript">
function myFunction()
{
var category_name = document.forms["insert"]["sub_category_name"].value;
//var image = document.forms["insert"]["file"].item();
var error = document.getElementById("error");
if(category_name=="" )
{
error.style.color="Red";
return false;
}
else
{
//message.innerHTML="Data Inserted!";
}
}
</script>
PHP 코드
<?php
echo "
<form name='insert' action='sub_categories.php' method='POST' onSubmit='return myFunction()' enctype='multipart/form-data'>
<table class='gridtable' border=2 bordercolor='#CCCCCC' cellpadding='10'>
<tr>
<th>
Sub-Category Name: </th><td> <input type='text' name='sub_category_name' ></td></tr>";
echo "
<tr>
<th>
Image1:</th><td> <input type='file' name= 'file' ></td></tr>
";
감사
ID로 파일 입력을 받고 값이 비어 있는지 확인하십시오.
if(document.getElementById('file').value=='') {//something here }
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다