2013-04-07 5 views
0

다음은 코드입니다. 두 개의 서로 다른 파일텍스트 상자의 값을 확인하는 방법

1 metadata.php이있다 'addAuthor'butoon 아약스 부하의 클릭에서 발생 이제 어떻게

<script> 
     $(document).ready(function(){ 

     $("#addAuthor").click(function(e){ 
     e.preventDefault(); 
     $.ajax({url:"n.php",type: "POST",data: ({id: '1'}),success:function(result){ 
     $("#div1").append(result); 
      }}); 
     }); 

     $("#removeAuthor").click(function(e){ 
       e.preventDefault(); 
       var lastNode = $("#div1").children().last(); 
       lastNode.prev().remove(); 
       lastNode.remove(); 
     }); 
     }); 
</script> 

    <div id="div1" > 

    </div> 
     <button id="addAuthor" >Add Author</button> 
     <button id="removeAuthor">Remove Author</button> 
<input type="submit" name="save" value="Save & Continue"> 

2 n.php

Name:<input type="text" name="txtname[]"> 
age:<input type="text" name="txtage[]"> 

모든 버튼 클릭 수만큼 n.php의 콘텐츠.

그리고 txtname [] 및 txtage []에는 모든 텍스트 상자의 값이 저장됩니다. 그러나 이러한 배열은 양식 게시에 값을 제공합니다.

그래서 양식 게시 전에 텍스트 상자의 값을 확인할 수 있습니까? 양식 게시에 대한 값의 유효성을 검사하는 경우 유효성 검사에 실패하면 metadata.php가 n.php의로드 된 콘텐츠와 함께 유지되지 않습니다.

그래서 어떻게해야합니까 ?? 양식을 제출하기 전에의 txtName 및 txtage을 확인하는 의미 경우

+0

**와 ** txtage **? PHP로? 이걸 보여줄 수 있니? – mehdi

+0

n.php 코드는 어떻게 생겼습니까? txtname 및 txtage 배열을 사용해야하는지 잘 모르겠습니다. – bestprogrammerintheworld

답변

0

, 당신은이 작업을 수행 할 수 있습니다 : 당신의 txtName ** 데이터 배열을 설정하는 방법

<script> 
    $(document).ready(function(){ 
     $("#div1 input[name='txtname']").each(function() { 
      // make test on the current txtname 
     }); 

     $("#div1 input[name='txtage']").each(function() { 
      // make test on the current txtage 
     }); 

     // uncomment this to prevent form submition 
     //return false; 
    }); 
</script> 
관련 문제