Home > Newsletter, Blog, and Other Topics > Topic

Dynamic textbox creation

Posted by sai rama 
This forum is now read only. You can not log in or make any changes. Please use the new forum linked above.
As of March 14, 2011, this forum has been replaced and is permanently set to read-only mode. This means you can view any existing post but cannot open new posts or reply to existing ones. The new forum is located athttp://www.larryullman.com/forums/If you need to post a message, you'll need to register there. If you have to post in order to follow up on a thread started here, well, that's going to be a bit of a pain. I would recommend just posting the appropriate information, or copying the original text from here, or linking to your thread here. I apologize for the inconvenience but this purge will make for better forums in the long run. Thanks.
Dynamic textbox creation
March 11, 2011 07:13AM
HI ,
I am trying to create text boxes dynamically , add the content of those textboxes and finally edit the column of the table.
        <script language='javascript'>
            function getBoxes2(){
                var val=document.getElementById("initTextBoxId2").value;
                var rid=document.getElementById("boxesId2");
                var str="";
                    alert("you have entered illegal value");
                    str +="<div id='allTextBoxes'>";

                    for(var i=1;i<=val;i++)
                        str +="<div>";
                        str +="    <span>new text box "+i+ " :</span>";
                        str +="    <span><input type='text' value='' size='30' /></span>";
                        str +="</div>";
                    str +="</div>";

                    str +="<div>";
                    str +="    <span><input type='button' value='Enter'  onClick='javascript:getSum2()'/></span>";

                    str +="</div>";

            function getSum2(){
                var txtBoxes=document.getElementById("allTextBoxes").getElementsByTagName("input");
                var sum=0;
                var val;
                for(var  i=0;i<txtBoxes.length;i++){
                    sum +=val;

                alert("total is ="+sum);
               // str+="<span><input type='text' value="sum" /></span>";
        <div style='padding-left:100px;padding-top:50px'>
            <span>Init textBox :</span><span><input type='text' value='' id='initTextBoxId2' size='30' onblur='javascript:getBoxes2()' /></span>
            <div id='boxesId2'></div>

now am not able to edit the total sum into the electricity_bill column through yii.
Please help me do this in yii php sir
Re: Dynamic textbox creation
March 12, 2011 02:56AM
First of all, I moved your post to the correct forum. You've posted a couple times now, and never in the right place. As for this particular question, you don't seem to be using Yii here at all.

Best Wishes,

Writer/Web Developer/Instructor
Forum Moderator
Re: Dynamic textbox creation
March 12, 2011 04:53AM
Sorry for it sir. I want to implement the above task in yii. Its getting difficult for me to do it as i am learning it now.
Basically please give me idea of where to implement that in yii.
Is it in the controller or in the model class.
Also tell me the need of Modules in yii.
Please help me sir
Re: Dynamic textbox creation
March 14, 2011 02:56PM
Okay, if you want to do this dynamically, you'll need to use JavaScript in the View to do it. You'll also need to adjust the Controller and the Model to allow for an array of text boxes. In short, this is not going to be easy.

You would use modules in Yii if you have separate components to a Web site. Like I might use a module for the forums area.

Best Wishes,

Writer/Web Developer/Instructor
Forum Moderator