2012-08-14 3 views
-1

내 루프에 varStatus이 있는데 js의 함수로 보내고 싶습니다.JSP 변수를 자바 스크립트 스 니펫으로 출력

onkeyup="clickableButton(this.value, ${newCommentStatus.index})" 

그러나 ${newCommentStatus.index}이 정의되지 :

이 내가 가진 것입니다. 이 값을 어떻게 보낼 수 있습니까 ??

덕분에

function clickableButton(text, id) { 
      if (text.length > 0) 
       document.getElementById("save-" + id).disabled = false; 
      else 
       document.getElementById("save-" + id).disabled = true; 
     } 
     ; 
+2

가 일부를 게시 할 수있는 방법을 시도해보십시오 당신이 자바 스크립트를 정리할 수 있고, 또한

... onkeyup="clickableButton(this.value, ${status.index})" ... 

:

이벤트 핸들러는 같을 것이다 좀 더 코드를주세요? – SpaceBeers

+4

'newCommentStatus' 란 무엇입니까? 'varStatus'는 어디에 있습니까? 템플릿 엔진 인'$ {} '은 무엇입니까? 무슨 일이야? "HTML 변수"같은 것은 없습니다. –

+0

JSP입니다. "varStatus"는 인덱스와 "atStart"및 "atEnd"에 대한 플래그와 같은 루핑 상태 정보를 제공합니다. 이것은 JSP 템플릿 엔진의 "forEach"구조를위한 것입니다. – Pointy

답변

-1

$ {newCommentStatus.index}는 표준 자바 스크립트가 아닙니다 사전

편집

<c:forEach items="${threadviewModel.emailToShowList}" var="row" varStatus="status"> 
    <form:form modelAttribute="commentFieldModel"> 
<span class="commentInput"><form:input id="commentInput" type="text" path="commentText" size="90" value=" " onkeyup="clickableButton(this.value, ${status.index})"/></span> 
             <div><input disabled="true" type="submit" id="save-${status.index}" name="_eventId_addComment" value="Save"/></div> 
            </div> 
          </form:form> 

자바 스크립트 코드 인.
JQuery 나 비슷한 것을 사용하고있는 것으로 의심됩니다. $ {newCommentStatus} .index를 시도하십시오.
이것은 몇 가지 가정하에 작동합니다.

+0

jQuery가 아니라 서버 측 JSP입니다. – Pointy

+0

JavaScript로 어떻게 작동하는지 어떻게 예상합니까? JSP는 한 번만 페이지를 생성하고 JavaScript는 여러 번 실행되고 처리됩니다. 페이지에 JSP로 생성 된 값은 하나만 가질 수도 있고 AJAX를 통해 JSP 변수를 가져올 수도 있습니다 –

+0

추가 정보로 내 질문을 편집했습니다. Thanks –

3

<c:forEach>은 "newCommentStatus"가 아니라 "status"변수를 호출합니다.

function clickableButton(text, id) { 
     document.getElementById("save-" + id).disabled = text.length <= 0; 
    } 
+0

그게 내가하고있는 일이야. id is undefined –

+1

@BeaGonzalezGutierrez 인덱스 값이 숫자이므로 아무 일도 일어나지 않습니다. 생성 된 페이지를 JSP 소스가 아닌 브라우저에서 볼 때 디버깅해야합니다. – Pointy

+0

Google 크롬 분석기를 사용하고 있으며 이것이 내가 얻은 것입니다. 스크린 샷을 게시 할 수 없습니다. –

0

대신

onkeyup="clickableButton(this.value, '${newCommentStatus.index}')"

관련 문제