Jquery Change not working on page reload

Discussion in 'jQuery' started by Ianz1234, Sep 11, 2012.

  1. #1
    Hi , i'am very new to jquery so please bare with me, I have a form that i use the "post" method to submit the form. When I selected the options without pressing submit the change() function works perfectly, but when i reload the page it does nothing. If it makes any difference i post the values back into the fields using <?php echo $_POST['value'];?>.

    Below is the code im using thanks in advance.


    Ian

    $(document).ready(function(){
    $("#currentLevel").change(function(){
    if ($(this).val() == "GCSE") {
    $("#institution").slideDown("fast"),
    $("#courseCompletitonGCSE").slideDown("fast");
    } else {
    $("#institution").slideUp("fast"),
    $("#courseCompletitonGCSE").slideUp("fast");
    }
    });
    // jQuery function end
    });
     
    Last edited: Sep 11, 2012
    Ianz1234, Sep 11, 2012 IP
  2. awood969

    awood969 Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    40
    #2
    You have 2 options;

    1) Submit the form via AJAX using jQuery's $.post or $.ajax requests, this will allow you to submit the form to PHP and receive a response without page reloading, this will allow the UI to remain constant on the page and prevent excess HTTP requests.
    2) Store a cookie with the last known visibility state and update this cookie every time the state changes. Then when the page reloads PHP can read this cookie and display the items appropriately.

    Personally I would recommend the 1st option, AJAX programming has a lot of advantages and the quicker you learn them the quicker your users will benefit :)

    Thanks
    Andrew
     
    awood969, Sep 19, 2012 IP