...

View Full Version : 'Undefined' problem



fatmess
03-07-2009, 02:04 PM
Hi,
I'm trying to get to the bottom of a problem & have chosen to temporarily use a button to see what's happening.
The variable $revnam contains a persons name



echo('<input type="button" onclick="favoriteNumber('.$revnam.')">');


The simple javascript function looks like this;



function favoriteNumber(myArg)
{
alert(myArg)
}


and the error is;



'TonyBlair' is undefined


could it be something to do with untrimmed space?
I haven't got a clue to be honest :(

abduraooft
03-07-2009, 02:13 PM
Post your parsed output(html+javascript) taken from browser's view source option.

fatmess
03-07-2009, 02:28 PM
Hi and thank you for your interest. I'm stumped!

HTML


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="book.css" rel="stylesheet" type="text/css">
<script src="autosuggest.js" type="text/javascript"></script>
<script src="book.js" type="text/javascript"></script>
<script src="bookread.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function BoxVal()
{
var bookvar;
bookvar = (document.frmone.tb.value);
showBOOK(bookvar);
}
</script>
<script language="javascript" type="text/javascript">
function favoriteNumber(myArg) {alert(myArg) }
</script>
<title>
</title>
</head>
<body>
<div id="nav1">
<a href="http://www.whatever.com/">sometext |</a>
<a href="http://www.whatever1.com/" target="_blank">sometext |</a>
<a href="http://www.whatever2.com/" target="_blank">sometext |</a>
<a href="http://www.whatever3.com/" target="_blank">sometext</a>
</div>
<div id="content1">
<span class="book">Enter data and then click the button</span>
<form name="frmone" action="">
<input type='text' style='font-family:verdana;width:300px;font-size:12px' id='tb' Value = "" >
<script type="text/javascript">
//XML file loading routine -

var customarray = new Array();
//code for IE
if (window.ActiveXObject)
{
//alert ('IE')
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load("book.xml");
}
// code for Mozilla, etc.
else if (document.implementation && document.implementation.createDocument)
{
//alert ('FF')
var xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load("book.xml");
}
// code for other browsers
else
{
alert('Your browser cannot handle this script');
}
var words = xmlDoc.getElementsByTagName('title');
//loop through all "title" tags
//alert (words.length);
for (i=0; i < words.length; i++)
{
//add them to the array
customarray[i] = words[i].firstChild.nodeValue;
//alert (customarray[i]);
}
//create the auto-completion text box object
new actb('tb', customarray);
</script>
</form>
<p>
<input type="button" id="Button1" value="Read review" onclick="BoxVal()" >
</p>
<div id="txtHint"><span class="book">Reviews will appear here.</span></div>
<div id="txtHint2"><span class="book">Specific reviews will appear here.</span></div>
</div>
</body>
</html>

PHP


<?php
echo ('<table class="tablea">');
$q=$_GET["q"];
$xmlDoc = new DOMDocument();
$xmlDoc->load("book.xml");
$x=$xmlDoc->getElementsByTagName('title');
for ($i=0; $i<=$x->length-1; $i++)
{

if ($x->item($i)->nodeType==1)
{
if ($x->item($i)->childNodes->item(0)->nodeValue == $q)
{
$y=($x->item($i)->parentNode);
}
}
}
$cd=($y->childNodes);

for ($i=0;$i<$cd->length;$i++)
{
if ($cd->item($i)->nodeType==1)
{
if($i==7)
echo ('</td></tr></table><br /><table class="tableb">');
if($i%8==7)
echo('<tr><td class="date">');
else echo('<tr><td class="date2">');
if($i%8==1 and $i>8)
$revnam = ($cd->item($i)->childNodes->item(0)->nodeValue);
echo($cd->item($i)->childNodes->item(0)->nodeValue);
if($i%8==1 and $i>7)
echo('&nbsp&nbsp&nbsp&nbsp<a href="javascript:getReaRevs('.$revnam.');">More from this reviewer</a>');
//the following line (button) is simply a way to find out why $revnam is undefined
echo('<input type="button" onclick="favoriteNumber('.$revnam.')">');
}
}
echo ('</table>');
?>

fatmess
03-07-2009, 02:59 PM
I have the solution;

this is the problem line;


"favoriteNumber('.$revnam.')">');

it should be;


"favoriteNumber(\''.$revnam.'\')"

thank you for any interest :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum