1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

storing array in hidden field and pass it to jquery

Discussion in 'HTML & Website Design' started by learnerabn, Sep 22, 2010.

  1. #1
    hi all,

    i want to get data of an text box to be filled in an .change event of a select box.
    but that data should be retrieved from db.
    i dont want to call ajax since it will take time to hit every time the select box changed,
    So i have an idea to store the data as an array in hidden field and pass it to the jquery..
    Is there any way to da this?
    Can any body tell me how to store array in hidden input field?

    Thanks in advance...
     
    learnerabn, Sep 22, 2010 IP
  2. jocurileus

    jocurileus Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you load the data at page load ?
    If you can, then use Json. make a variable and fill it with json data from php at page load then use jquery json functions to process it and search trough the arrays.
    You can also use the data function from jquery! If you need help with it post back I will try to help you.
     
    jocurileus, Sep 22, 2010 IP
  3. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes i can load it in page load but not able to get you clearly....
    can you explain it future....
     
    learnerabn, Sep 22, 2010 IP
  4. jocurileus

    jocurileus Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    make a variable in your page header with the data you want to search in json format.
    backend code
    
    $your_data = json_encode($your_data);
    ?>
    <script language="JavaScript">
    var mydata = <?php echo $your_data;?>;
    </script>
    <?php
    
    Code (markup):
    frontend code
    
    <script language="JavaScript">
    var mydata = json_string_here;
    </script>
    
    Code (markup):
    And you will process the data after with the help of jquery json functions
    http://php.net/manual/en/book.json.php
    Code (markup):
    http://api.jquery.com/jQuery.parseJSON/
    Code (markup):
     
    jocurileus, Sep 22, 2010 IP
  5. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry,Still i cant get you
    back end code should be just a php code there where comes js?

    and what is json used for here?
     
    learnerabn, Sep 23, 2010 IP
  6. jocurileus

    jocurileus Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I suggested json because it was easier to communicate between js and php. Do you have a page where you tried this ?
     
    jocurileus, Sep 23, 2010 IP
  7. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Still i havent put that page in server its under process...
     
    learnerabn, Sep 23, 2010 IP