Jump to content

Javascript onclick doesn't work fine in IE


Bogey

Recommended Posts

Hi all,

 

This is the line in the HTML-file:

<a href="javascript:void(0)" onclick="showConfirm('delete','<?php echo $rowOpdrachten['id'];?>')" class='button radius'>DELETE</a>

This is my javascript function:

var winConfirm = null;function showConfirm(kind,opdrachtID){var windowWidth = 250;var windowHeight = 100;var locX = ( screen.width - windowWidth ) / 2;var locY = ( screen.height - windowHeight ) / 2;var windowFeatures = "width=" + windowWidth + ",height=" + windowHeight +",screenX=" + locX + ",screenY=" + locY + ",left=" + locX + ",top=" + locY;if ( ( winConfirm != null ) && !winConfirm.closed ){winConfirm.close();}winConfirm = open( "", "winConfirm", windowFeatures );if (kind=='delete'){var theHTML = '<HEAD><TITLE></TITLE></HEAD>'+ '<BODY BGCOLOR="#CCE0F5">'+ '<CENTER><B>'+ 'Are you sure you want to delete item?'+ '</B><FORM NAME="buttonForm">'+ '<INPUT TYPE="button" VALUE="YES"'+ ' ONCLICK="opener.buttonClicked(0,'+opdrachtID+');self.close();"/>'+ ' '+ '<INPUT TYPE="button" VALUE="NO"'+ ' ONCLICK="opener.buttonClicked(1,'+opdrachtID+');self.close();"/>'+ '</FORM></BODY>';winConfirm.document.writeln( theHTML );}if (kind=='sold'){var theHTML = '<HEAD><TITLE></TITLE></HEAD>'+ '<BODY BGCOLOR="#CCE0F5">'+ '<CENTER><B>'+ 'Is it sold?'+ '</B><FORM NAME="buttonForm">'+ '<INPUT TYPE="button" VALUE="SOLD"'+ ' ONCLICK="opener.buttonClickedVerkocht(0,'+opdrachtID+');self.close();"/>'+ ' '+ '<INPUT TYPE="button" VALUE="NOT_SOLD"'+ ' ONCLICK="opener.buttonClickedVerkocht(1,'+opdrachtID+');self.close();"/>'+ '</FORM></BODY>';winConfirm.document.writeln( theHTML );}function buttonClicked(buttonChoice,opdrachtID){switch( buttonChoice ){case 0:showConfirm('sold',opdrachtID);break;case 1:alert ("Not deleted!");break;default:document.myForm.showResult.value = "(void)";break;}}function buttonClickedVerkocht(buttonChoice,opdrachtID){switch( buttonChoice ){case 0:window.location = "/test.php?a=yes&b=" + opdrachtID;break;case 1:window.location = "/test.php?a=no&b=" + opdrachtID;break;default:document.myForm.showResult.value = "(void)";break;}}}

It works fine in Chrome!!!

But in IE it does not work like it should...

 

The first window appears.

When clicked "NO" then the alert shows up, but it stays behind the first window, instead of in front of it.

When clicked "YES" then the first window closes, but the second window doesn't show up.

 

So when clicked "NO", then the alert has to show up in front of the first window.

When clicked "YES" the second window has to show up.

 

Any suggestions?

 

Edited by Bogey
Link to comment
Share on other sites

Still can't get it working....

 

I changed a line (putting in a Timeout):

 

function buttonClicked(buttonChoice,opdrachtID){switch( buttonChoice ){case 0://showConfirm('sold',opdrachtID);setTimeout(function (){showConfirm('sold',opdrachtID);}, 1000);break;case 1:alert ("Not deleted!");break;default:document.myForm.showResult.value = "(void)";break;}

 

But now I get this error message in Chrome:

Uncaught TypeError: Cannot read property 'document' of undefined

 

This has to do with this line:

 

winConfirm.document.writeln(theHTML);

 

I guess winConfirm is not opening a window?

 

 

In IE the error message gives me this:

Kan de eigenschap document van een niet-gedefinieerde verwijzing of een verwijzing naar een lege waarde niet ophalen

I english something like:

Can't get the property 'document' of an undefined reference or a reference to an empty value

Link to comment
Share on other sites

I think you are always going to have problems especially with IE and other browsers, producing html, AND most of all inputs by document.writeln, and linking back to JavaScript functions the way youi have, A better option is the have php page setup with html and link to external javascript, css etc like any normal page, and send values as querystring

 

example for your popup code

 

windowpopup.php

<?php$button1val = "";$button2val = "";$message = "";$suffix = "";if ($_GET['kind'] == 'delete') {    $message = "Are you sure you want to delete item?";    $button1val = "YES";    $button2val = "NO";} else {    $message = "'Is it sold?'";    $button1val = "SOLD";    $button2val = "NOT SOLD";    $suffix = "Verkocht";}?><!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>        <script  type="text/javascript" src="newjavascript.js"></script>    </head>    <body BGCOLOR="#CCE0F5">    <CENTER>        <B>            <?php echo $message; ?>        </B><FORM NAME="buttonForm">            <INPUT TYPE="button" VALUE="<?php echo $button1val; ?>"                   ONCLICK="buttonClicked<?php echo $suffix; ?>(0, <?php echo $_GET['id']; ?>);                           self.close();"/>                         <INPUT TYPE="button" VALUE="<?php echo $button2val; ?>" ONCLICK="buttonClicked<?php echo $suffix; ?>(1, <?php echo $_GET['id']; ?>);                    self.close();"/>        </FORM>    </center>    <hr>    <?php echo $_GET['kind'] . '<br>' . $_GET['id']; ?></body></html>

and call it using

winConfirm = window.open("windowpopup.php?kind=" + kind + "&id=" + opdrachtID, "winConfirm", windowFeatures);

newjavascript.js would have js function etc required, as you would normally with external js file, i used a very similar set up for playing short video files from a small popup window.

Link to comment
Share on other sites

Thank you very much for you answer....

I go try that one out (hopefully tomorrow).

 

I will come back to this again soon. And let you know if it did make it work like I wish! ;)

 

thnx!!!!!!!!

Link to comment
Share on other sites

Here I am again :crazy: lol

 

index.php

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="X-UA-Compatible" content="IE=8" /><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Language" content="nl" /><script type="text/javascript" src="/test.js"></script></head><body id="body"><a href="javascript:void(0)" onclick="showDelete('delete','001')">Delete</a></body></html>

test.js

winConfirm = null;function showDelete(kind,opdrachtID){ alert ("showDelete"); var windowWidth = 250;var windowHeight = 100;var locX = ( screen.width - windowWidth ) / 2;var locY = ( screen.height - windowHeight ) / 2;var windowFeatures = "width=" + windowWidth + ",height=" + windowHeight +",screenX=" + locX + ",screenY=" + locY + ",left=" + locX + ",top=" + locY;winConfirm = window.open("windowpopup1.php", "winConfirm", windowFeatures);}function showDeleteNEW(){ alert ("showDeleteNEW"); var windowWidth = 250;var windowHeight = 100;var locX = ( screen.width - windowWidth ) * 5;var locY = ( screen.height - windowHeight ) * 5;var windowFeatures = "width=" + windowWidth + ",height=" + windowHeight +",screenX=" + locX + ",screenY=" + locY + ",left=" + locX + ",top=" + locY;winConfirm = window.open("windowpopup2.php", "winConfirm", windowFeatures);}function buttonClicked(buttonChoice,opdrachtID){ alert ("buttonClicked");switch( buttonChoice ){case 0:alert ("case 0");showDeleteNEW();break;case 1:alert ("Not deleted!");break;default:document.myForm.showResult.value = "(void)";break;}}

windowpopup1.php

<?php$message = "Delete Item?";$button1val = "YES";$button2val = "NO";?><!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>    <head>        <meta charset="UTF-8">        <title></title>        <script type="text/javascript" src="/test.js"></script>    </head>    <body BGCOLOR="#CCE0F5"><center><b><?php echo $message;?></b><form name="buttonForm"><input type="button" value="<?php echo $button1val;?>" onclick="buttonClicked(0, '001');self.close();"/> <input type="button" value="<?php echo $button2val;?>" onclick="buttonClicked(1, '001');self.close();"/></form></center></body></html>

windowpopup2.php

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>    <head>        <meta charset="UTF-8">        <title></title>        <script type="text/javascript" src="/test.js"></script>    </head>    <body BGCOLOR="#CCE0F5"><center><p>TESTtestTEST</p></center></body></html>

The alert ("showDeleteNEW") from function showDeleteNEW() is shown, but windowpopup2.php I still can't get appear.

 

Sorry for all the inconvenience! ;)

 

Link to comment
Share on other sites

this did it:

windowpopup1.php

 

<form name="buttonForm"><input type="button" value="<?php echo $button1val;?>" onclick="opener.buttonClicked(0, '001');"/> <input type="button" value="<?php echo $button2val;?>" onclick="opener.buttonClicked(1, '001');self.close();"/></form>

windowpopup2.php

<form name="buttonForm"><input type="button" value="<?php echo $button1val;?>" onclick="opener.buttonClickedVerkocht(0, '001');self.close();""/> <input type="button" value="<?php echo $button2val;?>" onclick="opener.buttonClickedVerkocht(1, '001');self.close();"/></form>

 

thnx again!!!! :good:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...