Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Location
    United States
    Posts
    157
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Javascript to PHP

    Hello everyone!

    I have a question about how to send a javascript array to php to be able to use.

    I have a set up in html like:

    Code:
    <form action="">
    <fieldset style="width:205px;">
    <legend>Name</legend>
    <select id="names" name="names" onclick="addName(document.getElementById('names').value);" size="5" style="width:100px;">
    <option value="Bob">Bob</option>
    <option value="Fred">Fred</option>
    <option value="Sue">Sue</option>
    <option value="Angie">Angie</option>
    <option value="Rocky">Rocky</option>
    <option value="Matt">Matt</option>
    </select>
    <select id="list" name="list" onclick="setTimeout('removeName(document.getElementById('list').value)', 100);" size="5" style="width:100px;">
    
    </select>
    </fieldset>
    <input type="submit" value="FIGHT!" onclick="viewList();return false">
    </form>
    viewList function:
    Code:
    function viewList() {
    
    var final = document.getElementById('list');
    var array = new Array();
    for (var i = 0; i < final.options.length; i++) {
    array.push(final.options[i].value);
    }
    alert (array);
    }
    I know this alerts the list values, but I am unsure how to pass this to php to be able to use, as I assume I'll have to take a different approach, but thought I'd ask. Thanks again.
    Last edited by votter; 07-05-2010 at 05:41 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2009
    Location
    United States
    Posts
    157
    Thanks
    8
    Thanked 4 Times in 4 Posts
    nvm, I came up with a solution. Thanks for those who took the time to look at this. .

    This may be closed.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What was your solution? Others would like to know.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Regular Coder
    Join Date
    Oct 2009
    Location
    United States
    Posts
    157
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Yeah, my bad for not including it.

    I decided to assign the array to another variable, say:

    var test = array.toString();

    then I send test through the request and $_POST it to php, this is how I did it. I then exploded the string to get each result.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •