I have five lists (select) that are populated with php / mysql and jquery. I use this script: http://bit.ly/3YTAXe

When I post my form and the new page appears, I redisplay my five list and I want my 5 lists will populate with the values ​​posted.

I think I'd have to simulate the event "change" or something like that. I do not think my code can help (it's inside the smarty and many other things).

Does anyone can help me from the example code that is in the link above?

有帮助吗?

解决方案

try .trigger()

$('#yourselect').val('yourvalue');
$('#yourselect').trigger('change');

It can also be chained into a single statement:

$('#yourselect').val('yourvalue').trigger('change');

其他提示

a standard post action ask the server for a new page, which has no natural "memory" of the the form posted. So you have 3 basics options:

  1. send the values back from your servers
  2. use cookies to store them, and javacript to handle the cookies
  3. use jquery $.post instead of the standard post.

I prefer the 3rd option. jquery will send the form in ajax, and handle the response from the server inside the actual page. Of course, you have to "event.preventDefault" on the form submit button click (or in $('form').submit). Personally, I don't define any "action=" tag in forms supposed to be sent by $.post (i use a variable inside the $.post block).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top