Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Rewritten: jQuery / How do I use an array

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25197
    Benjamin
    Participant

    I removed my other post, because it was too long…and have revised my question, to simplify things.

    Situation: I have a series of checkboxes on a page, and each time a box is clicked, the value gets amended an array, then take the content of that array and build a url which should be loaded using .load. If the box is unchecked, I would like that value removed from the array and url rebuild and new page loaded.

    Question 1: Once a box is clicked how can I store that value to an array?
    Question 2: How do I build the .load url with an array?

    Here is the code I have so far…which works (kinda)

    Code:

    This only works for one checkbox at a time…as there is currently no array. Can someone explain how I can store a clicked value?

    I kinda think I need to do something more like…

    If a box is checked, see what other boxes are checked and then send the values of all the boxes that are checked.

    Then, when a box is unchecked, check what boxes are checked and then resend the values in a url. Thoughts?

    Thanks!

    #59404
    Mr KiTT3N
    Member

    The way you got your code working is everytime they click on a checkbox it will post information to server and load

    From how you are explaining im not sure what the end product is supposed to do anyways to answer you question if you want to store all the checkboxs in an array it would be done like this

    Code:



    From the example above the array will have ["something","somethingElse"]

    For second Question:

    Depends on what language you are using, python, perl, php, ruby ect? but the universal way is to send a long string

    Code:



    This will send "something, somethingElse" to the sever

    ((php: $_POST == "something, somethingElse" ))

    Then you could split that string back into a array or defintion list (all depending on the language)

    #59409
    Quote:
    $.post(‘/link/to/file/’, {data : checkData.join(‘, ‘)} );

    That is not the best way to send data to a php script.

    The most efficient way is to use a subscripted variable, this way the data will be accessible as an array in the php script.

    For example:

    Code:
    $.post(‘/link/to/file/’, { ‘data[]’ : checkData });

    Now in php the posted data will be available as an array:

    $_POST[0]
    $_POST[1]
    etc…

    #59412
    Mr KiTT3N
    Member

    Your probably right

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.