2010-08-11 2 views
0

이 질문은 solving my last question 이후에 오는 것입니다. 숨겨진 양식에서 값을 얻고 싶습니다. 그러나 빈 문자열 만 가져 오려고하면 정보가 저장 될 때 정보를 저장하는 것으로 간주했지만 나중에 검색 할 수 있는지, 어떻게 검색 할 수 있는지 알고 싶습니다.숨겨 지거나 자동 생성되는 콘텐츠의 가치를 얻는 방법은 무엇입니까?

또한, 일부 자바 스크립트와 함께 즉석에서 생성 된 테이블이 있습니다 :

function createTable(){ 
     if (document.getElementById("invoiceFormat").rowNumber.value != ""){ 
      rows = document.getElementById("invoiceFormat").rowNumber.value; 
     } 

     var contents = "<table id='mt'><tr>"; 

     if (document.getElementById("invoiceFormat").cb1[0].checked){ 
      contents = contents + "<td class='htd'>Quantity</td>"; 
     }if (document.getElementById("invoiceFormat").cb1[1].checked){ 
      contents = contents + "<td class='htd'>Description</td>"; 
     }if (document.getElementById("invoiceFormat").cb1[2].checked){ 
      contents = contents + "<td class='htd'>Unitary Price</td>"; 
     }if (document.getElementById("invoiceFormat").cb1[3].checked){ 
      contents = contents + "<td class='htd'>Subtotal</td>"; 
     } 

     for (i=4; i<=k; i++){ 
      if (document.getElementById("invoiceFormat").cb1[i].checked){ 
       contents = contents + "<td>" + document.getElementById("invoiceFormat").cb1[i].value + "</td>"; 
      } 
     } 


     contents = contents + "</tr>"; 

     for (j=1; j<=rows; j++){ 
      contents = contents + "<tr>"; 
      for (l=0; l<=k; l++){ 
       if (document.getElementById("invoiceFormat").cb1[l].checked){ 
       hotfix = l +1; 
       contents = contents + "<td> <input id='cell" + j + "_" + hotfix + "' name='cell' type='text' size='15' /> </td>"; 
       } 
      } 
      contents = contents + "</tr>"; 
     } 

     contents = contents + "</table>"; 
     var createdTable = document.getElementById("mainTable"); 
     createdTable.innerHTML = contents; 

    } 

이 만들어지는 후에는 내가 지금까지 운없이 액세스하지만 시도했다, 난 그냥 얻을 수있는 사용자는 생성 된 입력 필드에 입력합니다. 어떻게해야합니까?

내가 jQuery를 함께 원시 자바 스크립트를 사용하고있어 도서관 유무에 관계없이 답변을 환영 있도록 :)

답변

0

document.getElementById를 ("invoiceFormat"). CB1 [3] 내가 모르는 모든 먼저 .checked를 무슨 ".cb1 [3]"여기에 의미 그래서 나는 그것을 무시하고 어떻게이 문제를 해결할 것이라고 말할 것이다 : ("invoiceFormat"귀하의 양식의 ID를 가정합니다.) 1) 귀하의 양식 집합 이름 속성에서 네가 가진 모든 분야. 이 방법을 사용하는 경우 document.getElementById("invoiceFormat").fieldName.value

과 같이 연결할 수 있습니다. 양식을 로컬 변수에 넣어야합니다. 당신이 고유 ID를 가지고 그냥 양식에 필드에 직접에서 getElementById를 사용하는 모든 분야를 제공)

var form = document.getElementById("invoiceFormat"); 
form.fieldName.value; 

이 훨씬 빨리 될 것입니다. 이 방법이 더 좋으면 고소하지는 않지만 항상 두 번째 것을 사용하고 있습니다. 나는 그것에 익숙해진다.

3) 더 많은 방법이 있지만 과도한 것일 수 있습니다. 양식 필드를 만들 때 개체 필드에 값을 넣지 않고 요소 자체를 넣을 수 있으며 심지어 closure에 숨길 수 있습니다. 그렇게하면 다음과 같이 부를 수 있습니다.

formElements.formFieldOne.value; 
관련 문제