Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 6th, 2008, 10:47 AM
Registered User
 
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 'style.display' null or not an object

Hello, I am really new to coding in javascript, and i have been tasked with migrating an app (Javascript embedded in HTML embedded in PHP) from a linux web server to a windows server. Unfortunately the migration hasn't worked and coding changes appear to be required. I am getting the 'style.display' null or not an object on this function:

 function greyOut(theBB){
 if($(theBB).style.display=="none"){
   $(theBB).style.display="block";
   }
 else{
   $(theBB).style.display="none";
   }
 }

where the code referencing this function is:
<a href="javascript:greyOut('bb<?php echo $thisDiv ?>')">X</a>

$thisDiv represents the microtime() function built into php.

Does anyone know what may be causing this?
Thanks in advance,
Sheel Shah

 
Old May 6th, 2008, 11:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There's nothing with the JavaScript, you need to show the page's actual HTML source. Unless PHP is running on the server then the line:
Code:
<a href="javascript:greyOut('bb<?php echo $thisDiv ?>')">X</a>
will not have been processed by the PHP library and so the id of the div will not have been inserted.

--

Joe (Microsoft MVP - XML)
 
Old May 6th, 2008, 12:37 PM
Registered User
 
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Joe,

Thanks for answering. Here's the full code for the page:

<?php
include "PEAR.php";
require_once "Date.php";
header("Content-Type: text/xml");
echo "<"."?xml version=\"1.0\" encoding=\"ISO-8859-1\"?".">";
?>
<ajax-response>
        <response type="element" id="gameBoard">

<?php

$beginDate = $_POST['startDate'];
$endDate = $_POST['endDate'];

$dateParts1=explode("/", $beginDate);
$dateParts2=explode("/", $endDate);

$numberOfDays = Date_Calc::dateDiff($dateParts1[0], $dateParts1[1], $dateParts1[2],$dateParts2[0], $dateParts2[1], $dateParts2[2]);
$numberOfDays = $numberOfDays+1;
#echo "<h3>For a ".$numberOfDays." day event starting ".$dateParts1[1]."/".$dateParts1[0]."/".$dateParts1[2]." and ending ".$dateParts2[1]."/".$dateParts2[0]."/".$dateParts2[2].".</h3>";
$getNextDay = Date_Calc::prevDay($dateParts1[0],$dateParts1[1],$dateParts1[2],'%m/%d/%Y');
for($i = 0; $i <= $numberOfDays; $i++){

$thisDiv = microtime();
?>



<div class="boundingBox" id="bb<?= $thisDiv ?>">

<label for="hotelID">Sleeping Room</label>
<input type="hidden" name="hotelID[]" value="hotelroom" />



<label for="date">Day and Date:</label>
<input type="text" name="stayDate[]" value=<?php echo $getNextDay ?> />



<label for="date">number of Rooms:</label>
<input type="text" name="numberOfRooms[]" value="1" />

<a href="javascript:greyOut('bb<?php echo $thisDiv ?>')">X</a>

</div>


<?php
$dateItem = explode("/", $getNextDay);

$getNextDay = Date_Calc::nextDay($dateItem[1],$dateItem[0],$dateItem[2],'%m/%d/%Y');
}

?>
        </response></ajax-response>

 
Old May 7th, 2008, 01:45 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's not what you need. You need to view-source and show the part of interest.

--

Joe (Microsoft MVP - XML)
 
Old May 7th, 2008, 02:24 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii sheel331!!

your CurrentCode is like
<div class="boundingBox" id="bb<?= $thisDiv ?>">
<a href="javascript:greyOut('bb<?php echo $thisDiv ?>')">X</a>
</div>
Ur javascript function looking for theBB as an object,and since theBB is not at all object,its a value,you need to modify this code.
<script language="javascript">
function greyOut(theBB){
 if($(theBB).style.display=="none"){
   $(theBB).style.display="block";
   }
 else{
   $(theBB).style.display="none";
   }
 }
</script>

at Client Side(in browser) this would look like
<div class="boundingBox" id="bb123">
<a href="javascript:greyOut('bb123')">X</a>
</div>
to execute this code you will only modify the script

<script language="javascript">
function greyOut(theBB){
 theBBObj=document.getElementById(theBB);

 if(theBBObj.style.display=="none"){
   theBBObj.style.display="block";
   }
 else{
  theBBObj.style.display="none";
   }
 }
</script>

************
So you need to cut copy past above javascript function only ,it will work.
Hope this will help you.

Cheers :)

vinod
 
Old May 7th, 2008, 11:41 AM
Registered User
 
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello again everyone,

I have resolved my own issue, but thanks to everyone for your help!

The issue was in the boundingbox, the reference to $thisDiv was incorrect. It was

<div class="boundingBox" id="bb<?= $thisDiv ?>">

when it should have been

<div class="boundingBox" id="bb<?php echo $thisDiv ?>">

really odd that it failed on that, but relieved that it works now!

Thanks again!






Similar Threads
Thread Thread Starter Forum Replies Last Post
'style' is null or not an object earhear Beginning PHP 0 December 4th, 2007 04:22 AM
new style object initialize in vc# 2008 express nooree General .NET 7 September 25th, 2007 04:05 PM
display Null or Not an object error kishy449 Classic ASP Professional 1 September 4th, 2007 01:21 PM
(axis) Return object in WS, with style="wrapped" u wakeup J2EE 0 July 17th, 2006 01:51 AM
Error: 'style.display' is null or not an object Adam H-W Javascript 4 April 22nd, 2004 08:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.