I have the following code:
<A HREF="coord.php" onclick="insertcoord()"><IMG SRC="test.php" BORDER=1 ISMAP></A>
<SCRIPT>
function insertcoord()
{
str = window.location.search
if (str == "")
document.write("<P>No coordinates specified.")
else {
commaloc = str.indexOf(",") // the location of the comma
document.write("<P>The x value is " + str.substring(1, commaloc))
document.write("<P>The y value is " +
str.substring(commaloc+1, str.length))
}
}
</SCRIPT>
Which works perfectly in Firefox. The coordinates are put forward to the browser and I can do as I wish to them.
Unfortunately the exact same page in IE returns the No coordinates specified error and I can’t for the life of me work out why.
Can anyone explain why this is happening?
This is working fine…
try saying alert(window.location.search );
you will get the part from ? including it. then u need to parse it.
Thanks for the help, but now I am even more confused.
In IE, it returns a blank alert box. In firefox, I get the alert box containing ?x,y where x and y are the coords.
Here is my full code:
<html>
<head>
</head>
<body>
<b>Click on the image to insert the next point.</b> Or
<form method="get" name="deletion">
<input type="hidden" name="deletion" value="deletecoord">
<input type="submit" value="Delete Last Step">
</form>
<A HREF="coord.php" onclick="insertcoord()"><IMG SRC="test.php" BORDER=1 ISMAP></A>
<SCRIPT>
function insertcoord()
{
str = window.location.search
alert(window.location.search);
if (str == "")
document.write("<P>No coordinates specified.")
else {
commaloc = str.indexOf(",") // the location of the comma
document.write("<P>The x value is " + str.substring(1, commaloc))
document.write("<P>The y value is " +
str.substring(commaloc+1, str.length))
}
}
</SCRIPT>
<?php
if (isset($_GET['clear'])) {
unset($_GET['clear']);
unset($_SESSION['points']);
}
if (count($_GET)) {
$click = array_keys($_GET);
$click = explode(',', $click[0]);
$_SESSION['points'][] = $click[0];
$_SESSION['points'][] = $click[1];
}
$CFG->dbhost = "localhost";
$CFG->dbname = "xxxxxxxxxxxxx";
$CFG->dbuser = "xxxxxxxxxxxxx";
$CFG->dbpass = "xxxxxxxxxxxxx";
$connection = mysql_connect ($CFG->dbhost, $CFG->dbuser, $CFG->dbpass);
mysql_select_db ($CFG->dbname);
mysql_query("insert into imagecoord (coord_x, coord_y) VALUES ($click[0], $click[1])");
if (($_GET['deletion'])=="deletecoord"){
echo "hello";
$result = mysql_query("SELECT coord_index FROM imagecoord ORDER BY coord_index DESC LIMIT 0,1");
$fetched_result = mysql_fetch_array($result);
$string = $fetched_result['coord_index'];
echo $string;
mysql_query("DELETE FROM imagecoord WHERE coord_index = $string");
}
?>
How can this work perfectly in Firefox, but not IE? I can understand the whole HTML/CSS rendering differences in the browsers, but surely this is a Javascript/PHP issue? Browser independent?
Any explanations would be appreciated!
document.write() can only be used while the page is loading.
I see no reason to use JavaScript for this. Why not just use PHP for everything?
I don’t think I’ve ever seen someone use ISMAP before.
With the exception of this minor IE issue I seem to be experiencing ISMAP is far simpler to use than any other solution I can find.
Thanks for your suggestion - I am currently looking into changing my code for PHP to grab the coordinates instead of passing them using the JS.
Thanks again.