• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
append dropdown menu in form

#1
Hi I'd like some help please. I have created a form in CodeIgniter in which I want to save the name of a movie and the actors who play in. My code looks like this:
PHP Code:
<?php echo form_open().PHP_EOL?>

    <div class="form-group">
        <label for="title">Title *</label>
        <?php echo form_input('title'set_value('title'html_escape($movie->title)), 'class="form-control"'); ?>
        <?php echo form_error('title'); ?>
    </div>

    <h4>Cast</h4>
    <button type="button" id="add_actor" class="btn btn-primary btn-sm">Add Actor</button>
    <hr>
    <ul class="list-unstyled" id="cast"></ul>

    <div class="form-group">
        <?php echo form_submit('save''Save''class="btn btn-primary"').PHP_EOL?>
    </div>

<?php echo form_close().PHP_EOL?>

<script>
 $(document).ready(function() {
 var output = '<li style="margin-bottom:5px;">\
                    <div class="row">\
                        <div class="col-md-6">\
                            <?php echo form_dropdown("actors"$actorsnull"class=\"form-control\""); ?>\
                        </div>\
                        <div class="col-md-6">\
                            <input type="text" name="character[]" class="form-control"\ placeholder="Character" />\
                        </div>\
                    </div>\
                </li>';

 $('#add_actor').click(function() {
 $('#cast').append(output);
 });
 });
</script> 

So what I'm trying to do basicly is when I click the "Add Actor" button the jquery will append a row in my form where it should have a dropdown menu for choosing the actor, and next to this dropdown an input field for typing the actor's character in the movie. When I click the "Add Actor" button again I will to the same process again to enter the next actor in the movie, etc etc.

However the code in the script tag doesn't work as I expected, In fact jquery complains for syntax error. I 'm checking my code and try some changes but no effect. Firebug shows: "SyntaxError: unterminated string literal"

How can I make this work properly?
Reply

#2
Check to see if you have movie title or actor name containing single or double quote. That may be why you get "unterminated string literal" error.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.