Subject: Hiding a form field when a check box value is selected 2007-10-10 - By swapna reddy
Back I have created an interactive PDF Form dynamically from a bean. It has multiple form fields like Textbox, selectbox,checkbox n so on... I am trying to figure out, how to hide a form fieled when a particular option of checkbox/radiobutton/selectbox is selected. Where do I need to trigger the event after creating a javascript function using writer.addJavaScript(..)? Is it at the parent checkbox level or at the option level? How do I call the Javascript, what wud be the action?? Any help regarding the same would be highly appreciated.....The piece of code am trying to execute is as follows: PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("C:/ /SamplePDFForm.pdf")); document.open(); writer.addJavaScript( "function actionOnChange(){var question=this.getField('Component(s) Origin') ;app.alert('<P>Component(s) Origin</P>:'+this.getField('<P>Component(s) Origin< /P>'));if(this.getField('Ruminant.Bovine').value=='On')){question.display = display.hidden;app.alert('Bovine value:'+this.getField('Ruminant.Bovine').value )} else question.display = display.visible;}",false); PdfPTable checkboxOptionsTable = new PdfPTable(3); checkboxOptionsTable.setWidthPercentage(100f); float[] relativeWidths = {5.0f,50.0f,45.0f}; checkboxOptionsTable.setWidths(relativeWidths); PdfFormField multipleCheckbox = PdfFormField.createCheckBox(writer); multipleCheckbox.setButton(PdfFormField.FF_MULTISELECT); multipleCheckbox.setFieldName(questionDataVO.getQuestionText().trim()); PdfAppearance cbOff = cb.createAppearance(10, 10); PdfAppearance cbOn = cb.createAppearance(10, 10); cbOff.rectangle(1, 1, 8, 8); cbOff.stroke(); cbOn.rectangle(1, 1, 8, 8); cbOn.stroke(); cbOn.moveTo(1, 1); cbOn.lineTo(9, 9); cbOn.moveTo(1, 9); cbOn.lineTo(9, 1); cbOn.fillStroke(); laQuestionOptions = questionBO.getAllQuestionOptions(questionDataVO .getQuestionId()); for (int j = 0; j<laQuestionOptions.size();j++){ QuestionOptionsVO questionOptionsVO = (QuestionOptionsVO) laQuestionOptions .get(j); questionOptionsVO = (QuestionOptionsVO) laQuestionOptions.get(j); PdfFormField multipleCheckbox1 = PdfFormField.createEmpty(writer); multipleCheckbox1.setFieldName(questionOptionsVO.getControlLabelText()); multipleCheckbox1.setValueAsName(questionOptionsVO.getControlLabelText()); multipleCheckbox1.setValueAsString(questionOptionsVO.getControlLabelValue()); multipleCheckbox1.setAppearanceState("Off"); multipleCheckbox1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", cbOff); multipleCheckbox1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", cbOn); if("Ruminant".equals(questionDataVO.getQuestionText())& "Bovine".equals (questionOptionsVO.getControlLabelText())) { multipleCheckbox1.setAdditionalActions(PdfFormField.AA_DOWN ,PdfAction.javaScript("actionOnChange();\r",writer)); } multipleCheckbox.addKid(multipleCheckbox1); PdfPCell cell = new PdfPCell(); cell.setCellEvent(new CheckboxFormField(writer,questionOptionsVO .getControlLabelText(),multipleCheckbox1)); cell.setBorderColor(Color.white); cell.setBorder(Rectangle.NO_BORDER); checkboxOptionsTable.addCell(cell); } Thanks Swapna.
swapna -- ---- ---- ---- ---- ---- ----- 5, 50, 500, 5000 - Store N number of mails in your inbox. Click here. <div>I have created an interactive PDF Form dynamically from a bean. It has multiple form fields like Textbox, selectbox,checkbox n so on...</div> <div> </div> <div>I am trying to figure out, how to hide a form fieled when a particular option of checkbox/radiobutton/selectbox is selected. Where do I need to trigger the event after creating a javascript function using writer .addJavaScript(..)? Is it at the parent checkbox level or at the option level? How do I call the Javascript, what wud be the action?? </div> <div> </div > <div>Any help regarding the same would be highly appreciated.....The piece of code am trying to execute is as follows:</div> <div> </div> <div >PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("C:/ /SamplePDFForm.pdf"));<BR>document.open();<BR><STRONG>writer.addJavaScript(<BR> "function actionOnChange(){var question=this.getField('Component(s) Origin');app .alert('<P>Component(s) Origin</P>:'+this.getField('<P>Component(s) Origin</P>'));if (this.getField('Ruminant.Bovine').value=='On')){question.display = display .hidden;app.alert('Bovine value:'+this.getField('Ruminant.Bovine').value)} else question.display = display.visible;}",false);</STRONG></div> <div> </div> <div>PdfPTable checkboxOptionsTable = new PdfPTable(3);<BR >checkboxOptionsTable.setWidthPercentage(100f);<BR>float[] relativeWidths = {5 .0f,50.0f,45.0f};<BR>checkboxOptionsTable.setWidths(relativeWidths);<BR >PdfFormField multipleCheckbox = PdfFormField.createCheckBox(writer);<BR >multipleCheckbox.setButton(PdfFormField.FF_MULTISELECT);<BR>multipleCheckbox .setFieldName(questionDataVO.getQuestionText().trim());<BR>PdfAppearance cbOff = cb.createAppearance(10, 10);<BR>PdfAppearance cbOn = cb.createAppearance(10, 10 );<BR>cbOff.rectangle(1, 1, 8, 8);<BR>cbOff.stroke();<BR>cbOn.rectangle(1, 1, 8, 8);<BR>cbOn.stroke();<BR>cbOn.moveTo(1, 1);<BR>cbOn.lineTo(9, 9);<BR>cbOn.moveTo(1, 9);<BR>cbOn.lineTo(9, 1);<BR>cbOn.fillStroke();<BR >laQuestionOptions = questionBO.getAllQuestionOptions(questionDataVO .getQuestionId());<BR>for (int j = 0; j<laQuestionOptions.size();j++){<BR> QuestionOptionsVO questionOptionsVO = (QuestionOptionsVO) laQuestionOptions.get(j);<BR> questionOptionsVO = (QuestionOptionsVO) laQuestionOptions.get(j);<BR> PdfFormField multipleCheckbox1 = PdfFormField.createEmpty(writer);<BR> multipleCheckbox1.setFieldName (questionOptionsVO.getControlLabelText());<BR> multipleCheckbox1 .setValueAsName(questionOptionsVO.getControlLabelText());<BR>  ;multipleCheckbox1.setValueAsString(questionOptionsVO.getControlLabelValue()); <BR> multipleCheckbox1.setAppearanceState("Off");<BR>  ;multipleCheckbox1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", cbOff); <BR> multipleCheckbox1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", cbOn);<BR><STRONG> if("Ruminant".equals(questionDataVO.getQuestionText()) & "Bovine".equals(questionOptionsVO.getControlLabelText()))<BR> { multipleCheckbox1.setAdditionalActions(PdfFormField.AA_DOWN ,PdfAction.javaScript("actionOnChange();\r",writer));<BR> }<BR></STRONG> multipleCheckbox.addKid(multipleCheckbox1);<BR> PdfPCell cell = new PdfPCell();<BR> cell.setCellEvent(new CheckboxFormField(writer ,questionOptionsVO.getControlLabelText(),multipleCheckbox1));<BR> cell .setBorderColor(Color.white);<BR> cell.setBorder(Rectangle.NO_BORDER);<BR> checkboxOptionsTable.addCell(cell);<BR>}</div> <div> </div> <div> </div> <div>Thanks</div> <div>Swapna.</div> <div> </div> <div> </div><BR><BR>swapna<p> 
<!--4--><hr size=1></hr> 5, 50, 500, 5000 - Store N number of mails in your inbox. <a href="http://in.rd.yahoo.com/tagline_mail_4/*http://help.yahoo .com/l/in/yahoo/mail/yahoomail/tools/tools-08 (See http://ols-08.ora-code.com).html/">Click here.</a> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ __ ____ ____ ____ ____ ____ ____ ____ ____ ____ iText-questions mailing list iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
|
|