简体   繁体   English

我如何发布由jQuery动态创建的文本框值

[英]how do i post textbox value which is dynamically created by jquery

i am working with codeigniter framework i am trying to use textboxes in HTML form when the user click the button a textbox will automatically generated by jquery but when i submit the form the other textbox values are posting correctly but i can't post the jquery textbox value. 我正在使用codeigniter框架,当用户单击按钮时,jquery会自动生成一个文本框,因此我尝试使用HTML形式的文本框,但是当我提交表单时,其他文本框的值正确发布了,但我无法发布jquery文本框值。

here is the jquery code: 这是jQuery代码:

  $("#button").live('click',function add(){ 
   $("#tblRel").append(
       '<tr ><td>'
    +'<input type="text" class="input_value_short" id="prova" name="jquery_txt" value="prova" />'+ 
       '</td><tr>'
   );
});

HTML: HTML:

  <?php echo form_open("validation/form_main");?>
  <table id="tblRel"  border="0">
      <tr>
          <td class="lable">Applicant Name:</td>
          <td colspan="3"><?php echo form_input(array('name'=>'applicant_name','class'=>'input_value_long','value'=>set_value('applicant_name'))) ?></td>
      </tr>
 </table>
 <?php echo form_submit(array('id'=>'submit','name'=>'Save','value'=>'Save record','class'=>'button_print'));?>

in the form_main() function i am posting like this: 在form_main()函数中,我这样发布:

    form_main(){
    $name        = $this->input->post('applicant_name');
    $jquery_txt  = $this->input->post('jquery_txt');
    }

i can get the value of $name but the $jquery_txt is empty can anyone help me please! 我可以获取$ name的值,但$ jquery_txt为空,任何人都可以帮帮我! and sorry form my poor english. 抱歉,我的英语不好。

      $("#button").live('click',function add(){ 
           $("#tblRel").append('<tr ><td><input type="text" class="input_value_short" id="jquery_txt" name="jquery_txt[]" value="prova" /></td><tr>');
       });

I guess your name and is are different for the textbox..Make it same and if you have more than one textbox change the name of the textbox into array otherwise you will get only one value after posting it. 我猜您的名称与该文本框的名称不同。.使其相同,如果您有多个文本框,请将文本框的名称更改为数组,否则在发布后将仅获得一个值。

Change the jQuery code to this, and it should work fine. 将jQuery代码更改为此,它应该可以正常工作。 Your problem was that you were adding the contents with the "submit" button's click, which would submit the form and the contents would get appended after the submit request. 您的问题是您要通过单击“提交”按钮添加内容,这将提交表单,并且内容将在提交请求后追加。

<script>
    $("form").live('submit',function add(){ 
   $("#tblRel").append(
       '<tr ><td>'
    +'<input type="text" class="input_value_short" id="prova" name="jquery_txt" value="prova" />'+ 
       '</td><tr>'
   );
       return true;
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM