/    Sign up×
Community /Pin to ProfileBookmark

function not defined?

I have a php script that pulls off details of employees and displays them in a table. I applied a javascript function which is supposed to let the user click on a name and make the hidden table for that person visible.

I keep getting the error “reveal is not defined”?

Why?

Below is the script:
[B][I](ajaxClass.js)[/I][/B]

function reveal(el)
{
if(document.getElementById(el).style.display = ‘none’)
{
document.getElementById(el).style.display = ‘block’;
}
else
{
document.getElementById(el).style.display = ‘none’;
}
}

[B][I]salesMatrix.php[/I][/B]
Top line = “<script language=”text/javascript” src=”JavascriptClasses/ajaxClass.js”></script>”

the bottom of the file in which the js function is called:

$arrMatrices = $objDV->getMatrices();

foreach($arrMatrices as $arrMatrix)
{
$strName = $arrMatrix[‘name’];
$intMatrixID = $arrMatrix[‘intUserID’];
$arrMatrixDets = $objDV->getMatrixDets($intMatrixID);

print “<tr><td><a href=”#” onClick=”reveal(‘” . $intMatrixID . ‘”);”>$strName<a/></td></tr>”;
print “</table>”;

foreach($arrMatrixDets as $arrMatrixDet)
{
print “<table border=1 id=’$intMatrixID’ style=”display:none;”>”;
$dtmAdded = $arrMatrixDet[‘dtmAdded’];
$strReference = $arrMatrixDet[‘intAdvancesID’];
$strReviewer = $arrMatrixDet[‘reviewer’];
print “<tr><td>$dtmAdded</td><td>$strReference</td><td>$strReviewer</td></tr>”;
}
print “</table>”;
}

print “</div>”;

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 28.2007 — You should have used a comparison, not an assignment:
<i>
</i>if(document.getElementById(el).style.display =[COLOR="Red"]=[/COLOR]'none')


On the other hand, table and table elements do not use the 'block' value for display in full DOM compliant browsers (that works only for IE) thus for a cross browser solution you should use a blank value
<i>
</i>function reveal(el){
var obj = document.getElementById(el);
obj.style.display=obj.style.display==''?'none':'';
}
Copy linkTweet thisAlerts:
@GarethHopauthorMar 28.2007 — I have changed the function, thankyou for highlighting my mistake, as you can tell I am a noob at Javascript.

I'm still getting the error "reveal not defined on line 1"

I have included the full salesMatrix.php script below:

&lt;script language="text/javascript" src="JavaScriptClasses/ajaxClass.js"&gt;&lt;/script&gt;

&lt;?php


<i> </i>function displayNewForm($arrSentData)
<i> </i>{
<i> </i> $objDV = new dvTools();

<i> </i> $arrGroups = $objDV-&gt;getSalesMatrixGroups();

<i> </i> print "&lt;table border=1&gt;";
<i> </i> print "&lt;form action='main.php?strPage=salesMatrix&amp;mode=add' method=post&gt;";

<i> </i> foreach($arrGroups as $arrGroup)
<i> </i> {
<i> </i> $strGroup = $arrGroup['varSalesMatrixGroupName'];
<i> </i> $intSalesMatrixGroupID = $arrGroup['intSalesMatrixGroupID'];

<i> </i> print "&lt;tr&gt;&lt;td colspan=6 bgcolor=#dddddd&gt;$strGroup&lt;/td&gt;&lt;/tr&gt;";

<i> </i> $arrQuestions = $objDV-&gt;getSalesMatrixQuestions($intSalesMatrixGroupID);
<i> </i> foreach($arrQuestions as $arrQuestion)
<i> </i> {
<i> </i> print "&lt;tr&gt;";

<i> </i> $strQuestion = $arrQuestion['varSalesMatrixQuestion'];
<i> </i> $intSalesMatrixQuestionID = $arrQuestion['intSalesMatrixQuestionID'];

<i> </i> print "&lt;td bgcolor=#ccccff&gt;$strQuestion&lt;/td&gt;";

<i> </i> $arrAnswers = $objDV-&gt;getSalesMatrixAnswers($intSalesMatrixQuestionID);

<i> </i> foreach($arrAnswers as $arrAnswer)
<i> </i> {
<i> </i> $varSalesMatrixAnswer = $arrAnswer['varSalesMatrixAnswer'];
<i> </i> $intSalesMatrixAnswerID = $arrAnswer['intSalesMatrixAnswerID'];

<i> </i> print "&lt;td bgcolor=#dddddd&gt;$varSalesMatrixAnswer &lt;input type=radio name='$intSalesMatrixQuestionID' value='$intSalesMatrixAnswerID'&gt;&lt;/td&gt;";
<i> </i> }

<i> </i> print "&lt;/tr&gt;";
<i> </i> }
<i> </i> }
<i> </i> $intAdvancesID = $arrSentData['ref'];
<i> </i> $strName = $arrSentData['strName'];
<i> </i> print "&lt;input type=hidden name='advances' value='$intAdvancesID'&gt;";
<i> </i> print "&lt;input type=hidden name='strName' value='$strName'&gt;";
<i> </i> print "&lt;tr&gt;&lt;td colspan=6&gt;&lt;input type=submit name='submit' value='submit'&gt;&lt;/td&gt;&lt;/tr&gt;";
<i> </i>}

<i> </i>function saveMatrix($arrSentData)
<i> </i>{
<i> </i> $objDV = new dvTools();

<i> </i> $intUserID = $_SESSION['intUserID'];
<i> </i> $intAdvancesID = $arrSentData['advances'];
<i> </i> $intReviewerId = $arrSentData['strName'];
<i> </i> $intInsertID = $objDV-&gt;saveSalesMatrix1($intReviewerId, $intAdvancesID, $intUserID);

<i> </i> foreach($arrSentData as $strKey=&gt;$strValue)
<i> </i> {
<i> </i> if(eregi("^[0-9]", $strKey))
<i> </i> {
<i> </i> $objDV-&gt;saveSalesMatrix2($strValue, $intInsertID);

<i> </i> }
<i> </i> }
<i> </i> print "&lt;center&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Saved Sales Matrix record&lt;b&gt;&lt;/center&gt;";
<i> </i>}


<i> </i>if(isset($arrSentData['mode']))
<i> </i>{
<i> </i> $strMode = $arrSentData['mode'];

<i> </i> switch($strMode)
<i> </i> {
<i> </i> case 'new':
<i> </i> displayNewForm($arrSentData);
<i> </i> break;

<i> </i> case 'add':
<i> </i> saveMatrix($arrSentData);
<i> </i> break;

<i> </i> case 'review':
<i> </i> getAvailableMatrices();
<i> </i> break;
<i> </i> }


<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> print "&lt;div style="position:absolute; width:300; height:200; top:100; left:100; background-color:#ccccff;"&gt;";

<i> </i> print "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;center&gt;&lt;table border=1&gt;&lt;form action='main.php?strPage=salesMatrix&amp;mode=new' method=post autocomplete='off'&gt;";
<i> </i> print "&lt;tr&gt;&lt;td&gt;&lt;input type=text id='advRef' name='ref'
<i> </i> onKeyup="checkLength('advRef', 'submitID', 'status', 'statusd' );" onClick="enterDetails('advRef');" value='Enter Advances Reference'&gt;&lt;/td&gt;&lt;td bgcolor=#ccccff
<i> </i> id='statusd'&gt;&lt;img src='graphics/exclamation.gif' id='status' border=0 &gt;&lt;/td&gt;&lt;/tr&gt;";
<i> </i> print "&lt;tr&gt;&lt;td colspan=2&gt;&lt;select name='strName'&gt;&lt;option&gt;--------------------------&lt;/option&gt;";

<i> </i> $objDV = new dvTools();

<i> </i> $arrAssignees = $objDV-&gt;getAssignees2();

<i> </i> foreach($arrAssignees as $arrAssign)
<i> </i> {
<i> </i> $strName = $arrAssign['name'];
<i> </i> $intAssignID = $arrAssign['intUserID'];

<i> </i> print "&lt;option value=$intAssignID&gt;$strName&lt;/option&gt;";
<i> </i> }

<i> </i> print "&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;";

<i> </i> print "&lt;tr&gt;&lt;td colspan=2&gt;&lt;input type=submit id='submitID' name='submit' value='submit' style="display:none;"&gt;&lt;/td&gt;&lt;/tr&gt;";
<i> </i> print "&lt;/center&gt;&lt;/table&gt;&lt;/form&gt;";
<i> </i> print "&lt;br&gt;&lt;br&gt;";
<i> </i> print "&lt;table border=1&gt;";

<i> </i> $arrMatrices = $objDV-&gt;getMatrices();

<i> </i> foreach($arrMatrices as $arrMatrix)
<i> </i> {
<i> </i> $strName = $arrMatrix['name'];
<i> </i> $intMatrixID = $arrMatrix['intUserID'];
<i> </i> $arrMatrixDets = $objDV-&gt;getMatrixDets($intMatrixID);

<i> </i> print "&lt;tr&gt;&lt;td&gt;&lt;a href="#" onClick="reveal('171');"&gt;$strName&lt;a/&gt;&lt;/td&gt;&lt;/tr&gt;";
<i> </i> print "&lt;/table&gt;";

<i> </i> foreach($arrMatrixDets as $arrMatrixDet)
<i> </i> {
<i> </i> print "&lt;table border=1 id='$intMatrixID' style="display:none;"&gt;";
<i> </i> $dtmAdded = $arrMatrixDet['dtmAdded'];
<i> </i> $strReference = $arrMatrixDet['intAdvancesID'];
<i> </i> $strReviewer = $arrMatrixDet['reviewer'];
<i> </i> print "&lt;tr&gt;&lt;td&gt;$dtmAdded&lt;/td&gt;&lt;td&gt;$strReference&lt;/td&gt;&lt;td&gt;$strReviewer&lt;/td&gt;&lt;/tr&gt;";
<i> </i> }
<i> </i> print "&lt;/table&gt;";
<i> </i> }

<i> </i> print "&lt;/div&gt;";
<i> </i>}
Copy linkTweet thisAlerts:
@KorMar 28.2007 — the php code is of no use for us. Show us the generated HTML code
×

Success!

Help @GarethHop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...