Re: Saving css state in javascript and passing to php via form submit

From: Date: Sun, 01 Apr 2007 05:39:23 +0000
Subject: Re: Saving css state in javascript and passing to php via form submit
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-251857@lists.php.net to get a copy of this message
On Fri, March 30, 2007 9:45 am, Tim wrote: > My issue is on page reload, i have a form on the same page, when a > category > is clicked, the categorie info displays and you can update the info > through > this form (table and form on same page). My issue comes when i post > the > data, the page comes back and my category tree folds up which is > normal > because all divs are set to "display:none;". Just fought through something like this today... <form id="styles_saver" ...> <input type="submit" onclick="save_styles();" /> </form> <script type="text/javascript"> function save_styles(){ var div; var styles_saver=document.getElementById('styles_saver'); foreach(divs as d){ div = divs[d]; styles_saver.innerHTML += '<input type="hidden" name="style["' + d + ']" value="' + div.style '" />'; } styles_saver.submit(); </script> This is all JS, obviously... > What are the technologies IF there are any and what should i look up > to find > docs that cover this type of datatransfer ie: javascript->php. So now in the PHP part, to force this at least nominally on-topic, you have a nice array in $_POST['styles'] with an index by div in order, that you'd process like any $_POST value which is an array: if (isset($_POST['styles']) && is_array($_POST['styles'])){ foreach($_POST['styles'] as $d => $style){ //do something with div's $style, indexed by $d } } You could presumably get each div's id with div.id or somesuch, and use that instead of 'd' above. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#251857) next »