简体   繁体   中英

How to append php code within the javascript

In this my textboxes are generated by using JavaScript.In my controller I place the code for CodeIgniter validation. But I am confused about how to put the

           <?php echo form_error(); ?>

how to append this in javascript

                                     <div id='exp_error'> 
                                     <?php echo validation_errors(); ?> 
                                      </div> 

but this message displayed in all places..I want only in my link

script

          <input name="exp_amount_'+unqid1+'" id="id_'+unqid1+'" type="text" '+
        'class="form-control" placeholder="Enter '+name+' expense amount" style="margin-right:20px;" required>'
        +'<input name="comment_'+unqid1+'" type="text" id="comment"  class="form-con" placeholder="Comments" style="margin-right:20px;" required ></div >' ;

controller

          $this->form_validation->set_rules('exp_amount_'.$required_id, 'Expense Amount', 'required|numeric');
        $this->form_validation->set_rules('comment_'.$required_id, 'Comments', 'required');

The Javascript has to be in the "view" that is corresponding to the Action in the controller, otherwise this wont work. Because the PHP part is not getting executed in the server. It's getting generated in the client side and so, it's taking as plain HTML. Hope u understood my point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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