how to take javascript array values in php form

Javascript coding ..

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Fri Dec 23, 2011 1:02 pm

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
        $counter = 0; // initialize 0 for limitting textboxes
            if ($counter < 10)
                $('#buttondiv').append('<div><label>'+$counter+' Roommate Name:</label><input type="text" name="textbox[]" class="textbox" value="" /></div>');
                alert('You cannot add more than 10 textboxes');

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

            alert($('.textbox').serialize()); // use serialize to get the value of textbox

            $('#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> <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>

i want to insert text boxes values into my database, can anyone tell me how can i do this??

New php-forum User
New php-forum User
Posts: 45
Joined: Thu Sep 15, 2011 1:09 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.

Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 2 guests