2013-12-20 5 views
0
<script type="text/javascript"> 


$(document).ready(function(){ 

var count=$('#option1').val(); 
var counter = 1; 

$("#addButton").click(function() { 

if(counter>count){ 
     alert("Only "+count+" textboxes allow"); 
     return false; 
} 

var newTextBoxDiv = $(document.createElement('div')) 
    .attr("id", 'TextBoxDiv' + counter); 

newTextBoxDiv.after().html('<input type="radio" name="answer" id="answer" value="' + counter + '" /><label>Option #'+ counter + ' : </label>' + 
     '<textarea name="textbox' + counter + 
     '" id="textbox' + counter + '" value="" />'); 

newTextBoxDiv.appendTo("#TextBoxesGroup"); 

tinymce.init({ 
     selector: "textarea", 
     force_p_newlines : false, 


    plugins: [ 
      "advlist autolink autosave image link lists charmap print preview hr anchor pagebreak spellchecker", 
      "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", 
      "table contextmenu directionality emoticons template textcolor paste fullpage textcolor" 
    ], 

    toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect | cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media | inserttime preview ", 
    toolbar2: "forecolor backcolor | table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft ", 

    image_advtab: true, 
    menubar: false, 
    toolbar_items_size: 'small', 

    style_formats: [ 
      {title: 'Bold text', inline: 'b'}, 
      {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}}, 
      {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}}, 
      {title: 'Example 1', inline: 'span', classes: 'example1'}, 
      {title: 'Example 2', inline: 'span', classes: 'example2'}, 
      {title: 'Table styles'}, 
      {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'} 
     ], 

     templates: [ 
       {title: 'Test template 1', content: 'Test 1'}, 
       {title: 'Test template 2', content: 'Test 2'} 
     ] 

}); 
//add tinymce to this 
tinyMCE.execCommand("mceAddControl", false, 'txt'+counter); 

    counter++; 
}); 

</script> 




<form method="post" name="myForm" id="form" action="upload" onsubmit="return validateForm()" > 
<div id='TextBoxesGroup'> 
    <div id="TextBoxDiv0"> 
     <label>Selection: </label><select name="sel" id="sel" > 
      <option selected="true" style="display:none;">Select </option> 
<% 
    ResultSet rsta1=st.executeQuery("SELECT DISTINCT term FROM termwhere term not like 'null'"); 
    while(rsta1.next()) { 
     out.write("<option value=" + rsta1.getString("term") + ">" + rsta1.getString("term") + "</option>"); 
    } 
%> 
     <label>Question: </label><textarea id='textbox0' name="textbox0"></textarea> 
     <input type="hidden" name="option1" id="option1" value="<%=options21 %>"/> 
    </div> 
</div> 
<input type='button' value='Add Button' id='addButton' /> 
<input type='button' value='Remove Button' id='removeButton'/> 
<input type='submit' value='Submit'/> 
</form> 

위의 Jquery를 사용하면 추가 버튼을 누르면 더 많은 텍스트 영역이 나타납니다.이 페이지의 제출도 작동합니다. 다음에 다시 돌아올 때 문제가 발생합니다.양식은 이전 데이터를 유지합니다.

이전에 텍스트 영역에 입력 된 모든 데이터가 다시 나타나고 동일한 이전 데이터가 텍스트 영역에 채워집니다. 양식 필드가 비어 있도록 어떻게해야합니까?

또 하나의 문제는 새로운 텍스트 필드를 추가 할 때 데이터가 이전 데이터로 새로 고쳐집니다. 예를 들어.

텍스트 영역에 텍스트를 추가하고 입력 한 텍스트가 사라지거나 이전 텍스트가 나타납니다 (위에서 설명한대로 제 1 번째 문제가 나타납니다). 마찬가지로 추가 버튼을 다시 누르면 이전 2 개의 텍스트 필드가 나타납니다 비어 있거나 이전 텍스트가 나타납니다. 왜 이런 일이 발생합니까? >https://developer.mozilla.org/en-US/docs/Mozilla/How_to_Turn_Off_Form_Autocompletion

또는

빈 자바 스크립트를 사용하여 양식

formObject.reset -

+0

비어있는 텍스트 영역에 브라우저 캐시 문제 일 수 있지만 '$ ('# textbox0 '). val (' ');'on the rea dy. – KunJ

+0

거기에 JSP를 사용하여 캐시를 비우는 방법은 무엇입니까? –

+0

위의 스크립트에 url 응답을 추가했지만 작동하지 않습니다. –

답변

0

시도는

참조 정보를 유지에서 브라우저를 방지하기 위해 양식에 자동 완성 =를 추가()

+0

autocomplete doesnt work ... –

+0

도 나던 일 –

+0

그것은 내 모든 이전 프로젝트에서 작동하기 때문에이 이상하다. 브라우저 캐시를 비우고 테스트를 다시 시작하는 것이 좋습니다. 캐시가 실제로 어떤 일이 일어나고 있는지 보지 못하게되었습니다. – happy

관련 문제