By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

-> Updating a page when check box clicked (using Ajax)? <-

P: n/a
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 <DIVsection 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 <DIVof 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 <DIVsection.

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 <DIVvia 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: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
Feb 21 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Steve JORDI wrote:

<snip>
>
This does not work though if I display page.php into another
page <DIVsection 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 <DIVof my main page, the
javascript is never called. :-(

I'm missing something
Hi Steve,

Did you try via AJAX to get a piece of javascript like this:
<script type="text/javascript">
alert("did it!");
</script>

You'll see it won't work.
Javascript is NOT executed when returned and pasted in some div.
You need additional code to do that.

You better resend your problem to comp.lang.javascript because this is no
PHP issue.
If you do, ask them straight how to get your Javascript executed that is
returned via AJAX, because as far as I can see, your situation with the
checkbox logic is not relevant.

Good luck!

Regards,
Erwin Moller
Feb 21 '07 #2

P: n/a
>You'll see it won't work.
>Javascript is NOT executed when returned and pasted in some div.
You need additional code to do that.
Ah ok. I thought so.

>You better resend your problem to comp.lang.javascript because this is no
PHP issue.
If you do, ask them straight how to get your Javascript executed that is
returned via AJAX, because as far as I can see, your situation with the
checkbox logic is not relevant.
Ok I will thanks.
Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
Feb 21 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.