开发者

How to add textboxes to a divved area using jquery

开发者 https://www.devze.com 2023-03-20 14:06 出处:网络
Hi im using codeigniter PHP with jquery javascript function to create a textbox for time which is formatted.

Hi im using codeigniter PHP with jquery javascript function to create a textbox for time which is formatted.

I want the jquery function to add my textbox to the row of other textboxes instead of adding them to the bottom of the page.

Picture --> http://i.imgur.com/K9PiT.jpg

Here is my php file. It is messy I know but I am new to all of this.

        <script type="text/javascript"> var i = 0; </script> 

<?php
        for ($i=0; $i< 20; $i++)
        {


?>

   <script type="text/javascript">     

         var input = $("<input>", { //this bit will be removed in the form
                name: 'time'+i,
                val: '00:00:00',
                maxlength: '8',
                size: '5'
            });
            i++;
            input.click(function() {

                $(this).prop({
                    selectionStart: 0,
                    selectionEnd: 0
                });

            }).keydown(function() {

                var sel = $(this).prop('selectionStart'),
                    val = $(this).val(),
                    newsel = sel === 2 ? 3: sel;
                    newsel = sel === 5 ? 6: newsel;

                $(this).val(val.substring(0, newsel) + val.substring(newsel + 1))

                .prop({
                    selectionStart: newsel,
                    selectionEnd: newsel
                });
            });

            $('body').append(('#timearea_DIV').html());

         </script>

            <?php
      echo '<div id="timearea"></div> //THIS IS WHERE THE jquery generated textboxes must go!';

    //the event itself
            echo form_input ('event'.$i , set_value ('event'.$i)); 
    //supplies used
            echo form_input ('supplies'.$i, set_value ('supplies'.$i)); 开发者_StackOverflow社区
    //what is the manufacturer
            echo form_input ('manufacturer'.$i, set_value ('manufacturer'.$i));
    //quantity
            echo form_input ('quantity'.$i, set_value ('quantity'.$i));
    //was the event successful?
            echo form_dropdown ('success'.$i, $yesno , set_value ('success'.$i)); 
    //comment if necessary
            echo form_input ('comment'.$i , set_value ('comment'.$i)); 
     echo '<br/>';
    }

        //end of for loop

Thanks


You are appending it o body!! Place an empty div with an id where you want to add this text box.

Then for that div

(#divid).html('text box you want to add')

or append to that div

0

精彩评论

暂无评论...
验证码 换一张
取 消