JavaScript

108 views
Skip to first unread message

Davy Gunarso

unread,
Mar 25, 2013, 4:08:05 AM3/25/13
to joomla-de...@googlegroups.com

I add the following Javascript to my Joomla page and I get a blank screen on my homepage.  Please help cek my syntax.  Thanks.

<?php
function changeCSS() {
    $javascript .= 'document.getElementById("container").style.height=1000';
    return $javascript;
}
?>

<?php    $doc =& JFactory::getDocument();
        $doc->addScriptDeclaration( changeCSS() );
?>

Viper

unread,
Mar 25, 2013, 4:17:16 AM3/25/13
to joomla-de...@googlegroups.com
The value should be a percentage or in pixels.

PS! Do not use & for class. Only variable can be assigned by reference.

Aymeric Dourthe

unread,
Mar 25, 2013, 4:50:27 AM3/25/13
to joomla-de...@googlegroups.com
Hi,

$javascript have to be initialized before you concatenate any value.

$javascript =""; (for instance)

And said Viper, you need to add unit to your height.

$javascript .= 'document.getElementById("container").style.height="1000px"';   (for instance)

Hope to help.

Best regards,
Aymeric Dourthe
French web engineer

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Davy Gunarso

unread,
Mar 25, 2013, 7:05:24 AM3/25/13
to joomla-de...@googlegroups.com

ok, then now I have this:

<?php
$javascript = "";
function changeCSS() {
    $javascript .= 'document.getElementById("container").style.height="1000px"';
    return $javascript;
}
?>

<?php    $doc = JFactory::getDocument();

        $doc->addScriptDeclaration( changeCSS() );
?>

Still receive a blank screen on my Joomla page.

Aymeric Dourthe

unread,
Mar 25, 2013, 7:10:08 AM3/25/13
to joomla-de...@googlegroups.com
Hi,

by defining our $javascript variable outside you changeCSS function you
create something like a global variable (depending on the scope).

Something like that better fit your needs :

<?php

function changeCSS() {
$javascript = "";
$javascript .=
'document.getElementById("container").style.height="1000px"';
return $javascript;
}
?>

But i dont understand why you use concatenation in this case. Is there
some kind of missing code in your first message ?

Best regards,
Aymeric Dourthe
French web engineer

Le 25/03/2013 12:05, Davy Gunarso a �crit :

Davy Gunarso

unread,
Mar 25, 2013, 10:19:09 AM3/25/13
to joomla-de...@googlegroups.com

How to enable PHP display error?

I already change it to:


function changeCSS() {
    $javascript = "";
    $javascript .= 'document.getElementById("container").style.height="1000px"';
    return $javascript;
}

Still a blank screen on my Joomla product page (it's still offline)

Matt Thomas

unread,
Mar 25, 2013, 10:23:24 AM3/25/13
to Joomla! General Development
Why can't you just do:

$javascript = 'document.getElementById("container").style.height="1000px"';
$doc->addScriptDeclaration( $javascript );

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



Davy Gunarso

unread,
Mar 25, 2013, 3:16:30 PM3/25/13
to joomla-de...@googlegroups.com

Where would be the appropriate place to write the codes?  This is what I have and it gives me a blank screen.

<head>
<?php    $javascript = 'document.getElementById("container").style.height="1000px"'; ?>
</head>


<?php } else if (JRequest::getVar("option")=="com_virtuemart") {?>

<?php        $doc->addScriptDeclaration( $javascript );
?>
        <div id="left_menu">
            <jdoc:include type="modules" name="left_menu" style="xhtml" />
        </div>

        <div id="product_virtuemart">
            <jdoc:include type="message" />
            <jdoc:include type="modules" name="breadcrumbs" style="xhtml" />
            <jdoc:include type="component" />
            <jdoc:include type="modules" name="content" style="xhtml" />
        </div>
   
 <?php } ?>

Matt Thomas

unread,
Mar 25, 2013, 3:26:08 PM3/25/13
to Joomla! General Development
For the sake of testing the addition of the JavaScript, try removing the <?php } else if (JRequest::getVar("option")=="com_virtuemart") {?> and  <?php } ?> bits.

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



Davy Gunarso

unread,
Mar 25, 2013, 8:29:33 PM3/25/13
to joomla-de...@googlegroups.com


I did what you said and it turns out my whole home page turns into a blank screen.  Before, only my virtuemart product page.

Oh, I forget to mention that there are other codes in between (see the notes):



<head>
<?php    $javascript = 'document.getElementById("
container").style.height="1000px"'; ?>
</head>

.... // note:  there are other code in between


<?php } else if (JRequest::getVar("option")=="com_virtuemart") {?>



I comment out the virtuemart if condition. 

<?php //} else if (JRequest::getVar("option")=="com_virtuemart") {?>

... // other code

<?php //} ?>

Matt Thomas

unread,
Mar 26, 2013, 9:05:21 AM3/26/13
to Joomla! General Development
Does the page load fine if you comment out:

$doc->addScriptDeclaration( $javascript );

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



Davy Gunarso

unread,
Mar 26, 2013, 10:01:13 AM3/26/13
to joomla-de...@googlegroups.com

Yes, it does.

Nils Rückmann

unread,
Mar 26, 2013, 10:10:26 AM3/26/13
to joomla-de...@googlegroups.com
Sounds still like a typing error ;)
Can you just post your code on pastebin or similar ? (http://pastebin.com/)

JSamir

unread,
Mar 27, 2013, 2:04:05 AM3/27/13
to joomla-de...@googlegroups.com
Try using firebug (Firefox extension) and look in the Console-View. Any JS-Errors should be shown there (if responsible).

Davy Gunarso

unread,
Mar 27, 2013, 3:31:20 AM3/27/13
to joomla-de...@googlegroups.com

I copy paste the whole index.php code:

http://pastebin.com/mqNNMQYt

I can only see the nav background - the rest is a blank white page.

Tuan Pham Ngoc

unread,
Mar 27, 2013, 3:37:06 AM3/27/13
to joomla-de...@googlegroups.com
In your index.php file, you don't have the code 

$doc = JFactory::getDocument();

I believe that's the reason causing the blank page issue. Maybe the command add the top of the file :

$app = JFactory::getApplication();

Should be changed to  :

$doc = JFactory::getDocument();

Try to do that and it should solve your problem .

Davy Gunarso

unread,
Mar 27, 2013, 6:56:45 AM3/27/13
to joomla-de...@googlegroups.com

Thanks.   I no longer see the blank white page.  It just the virtuemart product page css have not change like specified.

Viktor Iwan

unread,
Mar 27, 2013, 11:58:12 PM3/27/13
to joomla-de...@googlegroups.com
Hello Davy,
this is out of topic, but i'm just asking if you was the one who works at Doxadigital.. if yes, please direct email me.. i help you to solve your problem..

Davy Gunarso

unread,
Mar 28, 2013, 7:32:44 AM3/28/13
to joomla-de...@googlegroups.com

If anyone else have good ideas how to solve this problem feel free to reply.  Thanks.

My virtuemart product css have not change as specified (1000px for height).

Aymeric Dourthe

unread,
Mar 28, 2013, 8:39:21 AM3/28/13
to joomla-de...@googlegroups.com
Hi,

post the code containing the "container" id, it ll be helpful.

Best regards,
Aymeric Dourthe
French web engineer

Le 28/03/2013 12:32, Davy Gunarso a �crit :

Davy Gunarso

unread,
Mar 28, 2013, 8:55:46 AM3/28/13
to joomla-de...@googlegroups.com

Here is part of it.


<?php       $javascript = 'document.getElementById("container").style.height="1000px"'; ?>
</head>
 
<body>
<div id="container">

It's a long code:  cek the rest:
http://pastebin.com/mqNNMQYt

you the css codes or what?

Don

unread,
Mar 28, 2013, 8:57:35 AM3/28/13
to joomla-de...@googlegroups.com
If you're trying to change the size of the container, why are you doing it in JavaScript ?

Sent from my iPhone

On Mar 28, 2013, at 7:39 AM, Aymeric Dourthe <aymeric...@gmail.com> wrote:

> Hi,
>
> post the code containing the "container" id, it ll be helpful.
>
> Best regards,
> Aymeric Dourthe
> French web engineer
>

Michael Babker

unread,
Mar 28, 2013, 9:13:34 AM3/28/13
to joomla-de...@googlegroups.com
You don't have $doc defined anywhere in your template, so when you try to do $doc->addScriptDeclaration(), it will fail.  For the sake of simplicity, change that line to this:

JFactory::getDocument()->addScriptDeclaration('document.getElementById("container").style.height="1000px"');

Reply all
Reply to author
Forward
0 new messages