简体   繁体   English

后值文本框div中的jQuery ajax响应stag

[英]jquery ajax response stag in post value text box div

Depends upon the select option value change click displaying textbox name and number of displaying text box will changed with my ajax.But i tried to validate that text box in submit button. 取决于选择选项值的更改,单击显示文本框的名称和显示文本框的数量将随我的ajax更改。但是我尝试在“提交”按钮中验证该文本框。 But that textbox values are not keep while submit button click... 但是在单击提交按钮时不会保留文本框的值...

MY question is ajax response div is not able to keep that values while submit??? 我的问题是ajax响应div在提交时无法保持该值???

Ajax response div: Ajax响应div:

<?php
foreach ($technical_skill as $skills){
?>
  <div class="form-group col-md-12">
    <div class="col-md-4">
      <label for="bsl"><?php echo $skills['techskills'];?></label>
    </div>
    <div class="col-md-8">
      <input type="text" class="form-control technicalskill" name = "technicalskill[<?php echo $skills['id']; ?>]" id="bsl">
    </div>
  </div><?php 
  }
?>

Jquery Ajax: jQuery Ajax:

$('#tskill').click(function(){
var parentid = $(this).val();
var text = $('option:selected', this).text();
    $.ajax({
      type:"POST",
      url:"index.php",
      data:{parentid:parentid},
      success:function(response){
        if(parentid == ''){
          $('#tech_head').css('display','none');
        }else{
          $('.tech_skill').html(response);
          $('.tech_group').text('Technical Skill: '+text);
          $('.hide-div').css('display','block');
        }
      }
    });
});

Simple solution: 简单的解决方案:

Save values to a hidden field, and have the submit function validate that value. 将值保存到隐藏字段,并让Submit函数验证该值。 Values should be saved to hidden field immediately upon select event. 选择事件后,值应立即保存到隐藏字段中。

Copy element data before sending a ajax request than you can use it later to 发送ajax请求之前先复制元素数据,然后再使用它可以

For example here is your code 例如,这是您的代码

<div id = 'myDiv'>
    <input type = 'text' id = 'myText' > 
    <input type = 'submit' id = 'submit' >
</div>

than use your jquery as 比使用您的jQuery作为

$('#submit').on('click', function(){
    temp = $('#myDiv');
    //your ajax code here 
    //now check with your elements value as temp.find('#myText').val();
})

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

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