You are here: -> Updating a page when check box clicked (using Ajax)? <- « PHP Programming Language « IT news, forums, messages
-> Updating a page when check box clicked (using Ajax)? <-

Posted by Steve JORDI on 02/21/07 15:17

Hi,
I'm having a little trouble trying to update a page content
when the user clicks a check box.
Basically, I need to reload a page to update its content depending
on that checkbox status.

I have added a checkbox that has an onClick event that calls
a javascript function that loads the form itself and adds
a GET variable in the url so that I can check which data I have
to display.

Mainly, the checkbox says "[x] Filtered"
When my page named "page.php" is called without parameters in
the url, it loads the data unfiltered.
If I click the checkbox, then I call "page.php?filtered="

In page.php I check whether isset($_GET['filtered']) to see
whether I have to filter the data before displaying it or not.

This works ok as long as I load "page.php" in the browser address
field.

This does not work though if I display page.php into another
page <DIV> section using Ajax. That's where I have no clue on
how to get the page refresh when clicking the check box.
When "page.php" is displayed into the <DIV> of my main page, the
javascript is never called. :-(

I'm missing something

Example:

the main page has a <DIV id="result"> section (result
is actually a document.getElementById("result") )
and uses

xmlhttp.open("GET", "mypage.php" );
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
result.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);

This correctly displays "page.php" in the main screen <DIV> section.

mypage.php
==========
function reloadPage() {
// Get the checkbox status
var cb = document.getElementById("cbFiltered") ;
if( cb.checked == true )
window.location="./mypage.php?filtered=";
else
window.location="./mypage.php";
}

and later in the code, I have this:
if( isset( $_GET['filtered'] ) )
showData( true ) ;
else
showData( false ) ;

Again, loading mypage.php in the browser works ok.
It doesn't when embedded into a <DIV> via Ajax.

Any solution to offer?

Thanks for any help.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: stevejordiK_I_L_LSPAM@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация