<script>
function close(){
window.open('alert_update.php?id=<? echo"$alertm[id]"; ?>','alert');
document.getElementById("alert").style.display="none";
}
</script>

The above script is what I am using to send a request as such to alert_update (the file that updates the database which is a small iframe 1px by 1px; but I also need it to onclick hide the div that is showing the alert (as well as holding the iframe) although for some reason it wont do either and so im not sure if its something to do with my code, I'm not great at javascript.

My code to execute the function is:

<a href="#" onClick='close()'>Okay</a>

what browser are you working in?

I did try editing my script above to visability="hidden" and on the div style visibility: visible. but it had no effect :(

Do you have Firebug, if not get the extension for firefox. press F12 to open it and then go to the console panel refresh the page and then say what the error message is, if there is an error message

Think I may have a javascript error on the page that is importing the page that holds the div with the div hide. The reason for this is the hide works fine on its page itself, although, when on the other page it doesn't work. its quite odd.

well, what is the error message?

When on the other page the error is:

element.style is undefined
[Break On This Error] element.style.display = 'none';

Public-image,

If I understand correctly, you want window.open('alert_update.php?id=<? echo"$alertm[id]"; ?>', 'alert'); to open an invisible child window, which will exist solely to handle the alert_update.php request (and its response).

You can do it this way but the code would be substancially different - chiefly in that a window opened with window.open(...) cannot be addressed with document.getElementById(...), which addresses DOM elements not windows.

In the old days (until about 5 years ago) the preferred approach would have been to use an iframe into which alert_update.php was loaded, but that approach has been superceded by AJAX.

Under AJAX (which is just a javascript pattern, not a language in its own right) an HTTP request is submitted and its response handled by javascript directly, not involving neither an iframe nor a child window.

If my understanding is correct, then yours is a classic problem for which AJAX is the most appropriate solution.

There are many good texts on AJAX out there on the internert and I won't try to better them. Try Googling "AJAX tutorial".

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.