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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux