简体   繁体   中英

add input fields dynamically with codeigniter

I'm trying to add dynamically input fields in Codeigniter when the user clicks the link but it doesn't seem to work. It will be really helpful if someone can figure it out.

My JS code is:

<script src="js/jquery.js" type="text/javascript">
    var count = 1;
    jQuery(document).ready(function() {
        $('p#add_field').click(function(){
           count += 1;
            $('#language').append(
                     '<strong>Language #' + count + '</strong><br />' 
                       + '<input id="language' + count + '"name="languages[]' + '" type="text" /><br />' );\

        });
    });
</script>

And my form code is:

<div id="container">
         some code

    <div id="body">
          some more code
        <div id="language">
           <p id="add_field"><a href="#">Προσθηκη Γλώσσας</a></p>
        </div>
    </div>
</div>
var count = 1;

$('p#add_field').click(function(){
    count += 1;
    var html='<strong>Language #'+ count +'</strong><br />'+'<input id="language'+ count +'"name="languages[]'+'" type="text" /><br />';
    $('#language').prepend(html);
});

remove all the spaces in appending html . javascript gives Unterminated String literal errors

fiddle

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