2013-08-01 3 views
0

를 사용하여 여러 선택 상자를 만들어 :액세스 ZF2 내가 젠드 프레임 워크 (2)를 사용하여 양식 객체에 다중 선택 상자를 생성 한 자바 스크립트

$contacts = new Element\Select('contacts'); 
$contacts->setLabel('All Contacts') 
     ->setAttribute('name', 'contacts') 
     ->setAttribute('multiple', 'multiple') 
     ->setAttribute('size', 10) 
     ->setOptions(array('options' => $users)); 
형태의 버튼을 누를 때 약간의 자바 스크립트를 실행하고 싶습니다

:

<select name="contacts[]" multiple="multiple" size="10"> 
,745 : 페이지가 여러 선택 요소의 이름을 생성 할 때

$moveAllRight = new Element\Button('moveAllRight'); 
$moveAllRight->setLabel('Move All ->') 
     ->setAttribute('value', 'Move All ->') 
     ->setAttribute('onClick', 'moveAll(this.form.contacts,this.form.newContacts)'); 

불행히도, []에 추가된다 내가 JS 함수 호출 내에서 이름을 변경 시도

:

->setAttribute('onClick', 'moveAll(this.form.contacts[],this.form.newContacts[])'); 

하지만 난 여전히 일을 점점 운을 가지고 있지 않다거야. 선택 상자에서 여러 옵션을 제거하면 작동하지만 모든 가능한 경우 여러 선택 상자를 사용하고 싶습니다. 이 작업을 수행 할 수있는 방법이 있습니까?

답변

0

양식 요소도 ID로 참조 될 수 있음을 알게되었습니다. 내가 사용하려고했던 이름과 동일한 값의 ID 속성을 설정합니다

요소는 페이지에 생성됩니다
$contacts = new Element\Select('contacts'); 
$contacts->setLabel('All Contacts') 
     ->setAttribute('id', 'contacts') 
     ->setAttribute('multiple', 'multiple') 
     ->setAttribute('size', 10) 
     ->setOptions(array('options' => $users)); 

:

<select name="contacts[]" id="contacts" multiple="multiple" size="10"> 

내가 원래 원처럼 나는 지금 그것을 참조 할 수 있습니다 ~까지 :

->setAttribute('onClick', 'moveAll(this.form.contacts,this.form.newContacts)');