using ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gayatrib
    New Member
    • Mar 2010
    • 4

    using ajax

    I want to insert number of data depending upon the requirement.
    Scenario:
    A user can add only one data and if he wants 2 data then he can click more.. the text box shows and he can enter the data and again he want to insert more data he has to click more.. and next text box will be seen accordingly the user can add as many data as he wish.

    How can this be possible?Please help.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    If I am reading you correctly, this would be a job for JavaScript.

    PHP is server-side, so to add input boxes to the page would require you to reload the page. And while you are reloading the page anyways, you may as well process the fields that are already filled in. - Which leaves you with a form that only has one field and is filled and submitted one at a time.

    With JavaScript, you can just add new boxes without having to go through any of that. - I would start by reading through these search results. I'm betting you will find something to work with there.

    Comment

    • itsloop
      New Member
      • May 2009
      • 18

      #3
      just provide an id which can will fill out the data from ajax and give the more link from where you can append data

      you can use

      Comment

      • gayatrib
        New Member
        • Mar 2010
        • 4

        #4
        Tahnk you for reply but..

        Thank you for your reply.

        This is the right solution for multiple tectbox.But, still my problem not solved.

        I have to repeat two, one textbox and one selectbox but cant get it..every time it only add only textbox.

        How can I? Any help?


        I have used this :

        Code:
        <script type="text/javascript">
        // Copyright 2008 Bontrager Connection, LLC
        // [url]http://www.willmaster.com/[/url]
        
        // When no form field name is provided, it is assumed 
        //   to be the default name with the default name 
        //   increment number appended.
        
        var DefaultName = "gift";
        var DefaultNameIncrementNumber = 0;
        
        // No further customizations required.
        function AddFormField(id,type,name,value,tag) {
        if(! document.getElementById && document.createElement) { return; }
        var inhere = document.getElementById(id);
        var formfield = document.createElement("input");
        if(name.length < 1) {
           DefaultNameIncrementNumber++;
           name = String(DefaultName + DefaultNameIncrementNumber);
           }
        formfield.name = name;
        formfield.type = type;
        formfield.value = value;
        if(tag.length > 0) {
           var thetag = document.createElement(tag);
           thetag.appendChild(formfield);
           inhere.appendChild(thetag);
           }
        else { inhere.appendChild(formfield); }
        } // function AddFormField()
        </script>
        
        
        <form>
        
        <table border="0"><tr><td align="right">
        Name: <input name="name"><br />
        Email: <input name="email">
        </td></tr></table>
        
        List gifts, one per field. If another field 
        is needed, click the "[more]" link.
        
        <div id="inhere">
        <input type="text" name="gift">
        </div>
        
        <a href="javascript:AddFormField('inhere','text','','','div')">[more]</a>
        <br />
        <input type="submit">
        </form>
        My code is:

        Code:
        <div id="a">
        							<select name="cmbName" id="cmbName" class="input">
        			                      {$enclosureName}
        							</select>
        							</div>
        							<b>  is  </b>
        							
        							  <input name="txtdistance" type="text" class="input" id="txtdistance" value="{$smarty.request.txtdistance}" size="9" />
        							<br /></div>
        								
        								<a href="javascript:AddFormField('cmb','cmbName','cmbName','{$enclosureName}','a')">[more]</a>
        								<br />
        Last edited by Dormilich; Mar 7 '10, 05:12 PM. Reason: Please use [code] tags when posting code

        Comment

        Working...