Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

how to take javascript array values in php form

Javascript coding ..

Moderators: macek, egami, gesf

how to take javascript array values in php form

Postby punitjain » Fri Dec 23, 2011 1:20 pm

Hello everyone i have a script which is dynamically adding textboxes correspond to the value i select in the combo/select box, but the problem is how i take that value to my php form so that i can insert that value into my database.
Here is the script:

Code: Select all
// JavaScript Document to add dynamic text boxes onto the registration form
    $(document).ready(function(){
        $counter = 0; // initialize 0 for limitting textboxes
        $('#buttonadd').click(function(){
            if ($counter < 10)
            {
                $counter++;
                $('#buttondiv').append('<div><label>'+$counter+' Roommate Name:</label><input type="text" name="textbox[]" class="textbox" value="" /></div>');
            }else{
                alert('You cannot add more than 10 textboxes');
            }
        });

        $('#buttonremove').click(function(){
            if ($counter){
                $counter--;
                $('#buttondiv .textbox:last').parent().remove(); // get the last textbox and parent for deleting the whole div
            }else{
                alert('No More textbox to remove');
            }
        });

        $('#buttonget').click(function(){
            alert($('.textbox').serialize()); // use serialize to get the value of textbox
        });

        $('#dropdownadd').change(function(){
            $('#dropdowndiv').html(""); // when the dropdown change set the div to empty
            $loopcount = $(this).val(); // get the selected value
            for (var i = 1; i <= $loopcount; i++)
            {
                $('#dropdowndiv').append('<div><label>'+i+' Roommate Name:</label><input type="text" name="textbox[]" class="textbox2" value="" /></div>');
            }
        });
    });




Here i am calling this into my form:

Code: Select all
...............................................
 <td><div id="dropdowndiv" class="input-container"><script type="text/javascript" src="js/dynamic_add_users.js"></script>
<!-- this is where textbox will appear --></div></td>
  </tr>
  <tr> <td><label for="no_of_roomates" id="label">how many roomates:</label></td><td>
  <div class="choices">
 

    <select id="dropdownadd">
        <option value="0">0</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
    </select>
</div>
</td></tr> 
.....................................



i want to insert text boxes values into my database, can anyone tell me how can i do this??
punitjain
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Dec 23, 2011 1:02 pm

Re: how to take javascript array values in php form

Postby mbrother » Sat Dec 24, 2011 2:49 pm

Won't those textboxes get included when you post your HTML form? I'm not sure I understand the problem.
mbrother
New php-forum User
New php-forum User
 
Posts: 45
Joined: Thu Sep 15, 2011 1:09 pm


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron