0

I have this code to append the input panel #yearPanel after the select box #before changed.

$("#before").change(function() {
    var selected = $('#before option:selected').text();

    if(selected == bankShowYear) {
        $(yearPanel).insertAfter("#yearAnchor");
        var value = $("#yearHiden").val();
        $("#year").val(value);
    } else {
        $("#yearPanel").remove();
    }
});

I want to keep the input value of #year in #yearPanel after submitting by PHP. I tried to store the value in #yearHidden and assign it to #year after all the input are rendered but it doesn't work.

How to keep the input value?

1
  • You might want to add the HTML and PHP to help clarify your problem. Commented Mar 1, 2013 at 3:57

3 Answers 3

1

Try this:

$("#before").change(function() {
    var selected = $('#before option:selected').text();

    if(selected == bankShowYear) {
        $(yearPanel).insertAfter("#yearAnchor");
        var value = $("#yearHiden").val();
        $("#year").val(value).attr('name', 'year');
    } else {
        $("#yearPanel").remove();
    }
});

Then, on your next page:

$("#year").value(<?php echo $_REQUEST['year']?>);

OR

 <input id="year" value="<?php echo $_REQUEST['year']?>" />
Sign up to request clarification or add additional context in comments.

Comments

1

your input needs a name attribute in order for it to be passed along to your serverside php script

1 Comment

still don't see a name attribute in the code. please add your html so we can clarify
0

You need to pass the value to PHP via a hidden field and PHP will have to render it on the next page. In other words the value needs to go from the client-side to the server-side and back to the client-side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.