문제

I have some code here that I use to change or swap images when moused over. This is the javascript code:

<script type="text/javascript" language="Javascript">

var imgdir = "category_icons/";

blank_icont = new Image;
blank_icont.src= imgdir+"blank_text.png";
vieworder_icon = new Image;
vieworder_icon.src = imgdir+"vieworder.png";
vieworder_icono = new Image;
vieworder_icono.src= imgdir+"vieworder2.png";
//vieworder_icont = new Image;
//vieworder_icont.src= imgdir+"vieworder.png";

function changeImages(name) { 
document.images[name].src = eval(name + '_icono.src');
document.images.icon_text.src  = eval(name + '_icont.src');
}

function changeImages2(name){ 
document.images[name].src = eval(name + '_icon.src');
document.images.icon_text.src  = eval('blank_icont.src');
    }
</script>

Inside my PHP script I have this bit of code:

$dynamiclist = '<table align="center" width="60%" border="0" cellspacing="5" cellpadding="8">
                        <tr height="10"><hr style="width: 60%;"></tr>
                        <tr>
                            <td width="30% valign="top" align="left"><img style="border: #66cc33 5px solid;" src="./menupictures/'. $picturepath . '" height="140" width="140" border="1"/></td>
                            <td width="40%" valign="top" align="left"> ' . $name . ' <br /> $' . $price . ' <br /><br /><a href="moreinfo.php?id=' . $id .'">More Info</a></td>
                            <td width="30% valign="top" align="left"><a onmouseover="changeImages("vieworder")" onmouseout="changeImages2("vieworder")" href="customize.php?id=' . $id .'"><img id="vieworder" src="category_icons
                                                                        /vieworder.png" alt="" name="vieworder" border="0"></a></td>

You'll notice where I try to use the functions changeImages. Is it not working because I can't use javascript this way? Or do I have my quotations incorrect? I've tried changing some things around by moving quotations, but nothing is working.

HERE IS THE FULL CODE:

<html>
<head>

<script type="text/javascript" language="Javascript">

var imgdir = "category_icons/";

blank_icont = new Image;
blank_icont.src= imgdir+"blank_text.png";
vieworder_icon = new Image;
vieworder_icon.src = imgdir+"vieworder.png";
vieworder_icono = new Image;
vieworder_icono.src= imgdir+"vieworder2.png";
//vieworder_icont = new Image;
//vieworder_icont.src= imgdir+"vieworder.png";

function changeImages(name) { 
document.images[name].src = eval(name + '_icono.src');
document.images.icon_text.src  = eval(name + '_icont.src');
}

function changeImages2(name){ 
document.images[name].src = eval(name + '_icon.src');
document.images.icon_text.src  = eval('blank_icont.src');
    }
</script>

</head>
<body>

<!-- This is where the table section starts -->
<table><tr height="50">&nbsp;</tr></table> 
</body>
</html>

<?php
/* ----------------------------------- CONNECTING AND QUERYING THE DATABASE -----------------------*/

require("database.php"); //connect to the database

$start = (isset($_GET['start']) ? (int)$_GET['start'] : 0); //setting the get function for pagnation

$result = mysqli_query($con,"SELECT * FROM menuitem WHERE type='kids'LIMIT $start, 3"); //mysql statement. first argument $starat specifies the offset of the first row to return, and the second specifies the maximum number of rows to return 
    if (!$result) {
        printf("Error: %s\n", mysqli_error($con));// Displays the error that mysql will generate if syntax is not correct.
        exit();
    }


echo '<table><tr height="20"></tr></table>

        <table height="50" width="60%" align="center" border="0" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td width="300" align="left"><font style="font-weight:bold;">Menu Items</font></td>
                <td width="400" align="left"><font style="font-weight:bold;">Menu Information</font></td>
                <td width="300" align="left"><font style="font-weight:bold;">Add to Order</font></td>
            </tr>
        </table>';
/* ----------------------------------- PULLING IN THE DATA -----------------------*/

//DYNAMIC PHP PULLING IN THE DATA AND SPITTING OUT THE RESULTS
while($row = mysqli_fetch_array($result))
{
    $id = $row['id'];
    $description = $row['description'];
    $picturepath = $row['picturepath'];
    $name = $row['name'];
    $price = $row['price'];

    $dynamiclist = '<table align="center" width="60%" border="0" cellspacing="5" cellpadding="8">
                        <tr height="10"><hr style="width: 60%;"></tr>
                        <tr>
                            <td width="30% valign="top" align="left"><img style="border: #66cc33 5px solid;" src="./menupictures/'. $picturepath . '" height="140" width="140" border="1"/></td>
                            <td width="40%" valign="top" align="left"> ' . $name . ' <br /> $' . $price . ' <br /><br /><a href="moreinfo.php?id=' . $id .'">More Info</a></td>
                            <td width="30% valign="top" align="left"><a onmouseover="changeImages(&quot;vieworder&quot;)" onmouseout="changeImages2(&quot;vieworder&quot;)" href="customize.php?id=' . $id .'"><img id="vieworder" src="category_icons
                                                                        /vieworder.png" alt="" name="vieworder" border="0"></a></td>
                        </tr>
                    </table>';
    echo $dynamiclist;
    }
도움이 되었습니까?

해결책

Jakobud is correct that the quotes are the problem, but the solution is different:

onmouseover="changeImages(&quot;vieworder&quot;)"

It's always important to consider the context when escaping stuff.

다른 팁

At a glance I'm guessing it's problems with your quotes. Try this:

onmouseover="changeImages(\"vieworder\")" onmouseout="changeImages2(\"vieworder\")"

Change this:

 onmouseover="changeImages(\'vieworder\')" onmouseout="changeImages2(\'vieworder\')"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top