0

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>
0

1 Answer 1

1
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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.