How to Show a Div using Javascript

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to Show a Div using Javascript

Marwa
Hello all,
I am new to Tapestry and to Web development in general but I have to
implement a simple web application for my research.

I use a div that when loading the page I need to hide it, so I use this
line:
 <div id="div1" class="grid3" scroll="true" style="display:none">
The div contains "inside it" a grid that will contain some elements after a
"load" button is pressed.
how can I unhide the div again "after pressing the load button"?

I know that I could do this with JS Line of code like:
 document.getElementById("div1").style.display ="";
But how and where can I add a javascrpt line of code directly in my Java
class?

Thansk in advance

--



*Marwa Hussein M. TA @ Information Systems Department Faculty of Computers
& Information Assuit University*
<[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: How to Show a Div using Javascript

Thiago H de Paula Figueiredo
Hello!

@Inject private JavaScriptSuport javaScriptSupport;

void beginRender() {

javaScriptSupport.addScript("document.getElementById("div1").style.display
= '';");
}

On Sat, Oct 3, 2020 at 10:06 AM marwa hussein <[hidden email]>
wrote:

> Hello all,
> I am new to Tapestry and to Web development in general but I have to
> implement a simple web application for my research.
>
> I use a div that when loading the page I need to hide it, so I use this
> line:
>  <div id="div1" class="grid3" scroll="true" style="display:none">
> The div contains "inside it" a grid that will contain some elements after a
> "load" button is pressed.
> how can I unhide the div again "after pressing the load button"?
>
> I know that I could do this with JS Line of code like:
>  document.getElementById("div1").style.display ="";
> But how and where can I add a javascrpt line of code directly in my Java
> class?
>
> Thansk in advance
>
> --
>
>
>
> *Marwa Hussein M. TA @ Information Systems Department Faculty of Computers
> & Information Assuit University*
> <[hidden email]>
>


--
Thiago
Reply | Threaded
Open this post in threaded view
|

Re: How to Show a Div using Javascript

Marwa
Hi Thiago,

Thanks a lot for your reply it works fine but the problem is using this
line of code in beginRender() function shows the "div" when the page is
loaded. but What I want is to show the div after a button is pressed.
When I used this line of code in the onSubmit() button function it gives
me  "No object of type
org.apache.tapestry5.services.javascript.JavaScriptSupport is available
from the Environment" exception!!
Could you explain this for me?

Regards,
Marwa

On Sat, Oct 3, 2020 at 10:01 PM Thiago H. de Paula Figueiredo <
[hidden email]> wrote:

> Hello!
>
> @Inject private JavaScriptSuport javaScriptSupport;
>
> void beginRender() {
>
> javaScriptSupport.addScript("document.getElementById("div1").style.display
> = '';");
> }
>
> On Sat, Oct 3, 2020 at 10:06 AM marwa hussein <[hidden email]>
> wrote:
>
> > Hello all,
> > I am new to Tapestry and to Web development in general but I have to
> > implement a simple web application for my research.
> >
> > I use a div that when loading the page I need to hide it, so I use this
> > line:
> >  <div id="div1" class="grid3" scroll="true" style="display:none">
> > The div contains "inside it" a grid that will contain some elements
> after a
> > "load" button is pressed.
> > how can I unhide the div again "after pressing the load button"?
> >
> > I know that I could do this with JS Line of code like:
> >  document.getElementById("div1").style.display ="";
> > But how and where can I add a javascrpt line of code directly in my Java
> > class?
> >
> > Thansk in advance
> >
> > --
> >
> >
> >
> > *Marwa Hussein M. TA @ Information Systems Department Faculty of
> Computers
> > & Information Assuit University*
> > <[hidden email]>
> >
>
>
> --
> Thiago
>


--



*Marwa Hussein M. TA @ Information Systems Department Faculty of Computers
& Information Assuit University*
<[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: How to Show a Div using Javascript

Thiago H de Paula Figueiredo
On Sun, Oct 4, 2020 at 8:37 AM marwa hussein <[hidden email]>
wrote:

> Hi Thiago,
>

Hello!


> Thanks a lot for your reply it works fine but the problem is using this
> line of code in beginRender() function shows the "div" when the page is
> loaded. but What I want is to show the div after a button is pressed.
>

In this case, just write the same JavaScript you'd do as if you weren't
using Tapestry.


> When I used this line of code in the onSubmit() button function it gives
> me  "No object of type
> org.apache.tapestry5.services.javascript.JavaScriptSupport is available
> from the Environment" exception!!
>

JavaScriptSupport is only available when the component is being rendered.
Form submission is not done during rendering, so you get this exception.

--
Thiago
Reply | Threaded
Open this post in threaded view
|

Re: How to Show a Div using Javascript

Marwa
On Mon, Oct 5, 2020, 2:22 PM Thiago H. de Paula Figueiredo <
[hidden email]> wrote:

> On Sun, Oct 4, 2020 at 8:37 AM marwa hussein <[hidden email]>
> wrote:
>
> > Hi Thiago,
> >
>
> Hello!
>
>
> > Thanks a lot for your reply it works fine but the problem is using this
> > line of code in beginRender() function shows the "div" when the page is
> > loaded. but What I want is to show the div after a button is pressed.
> >
>
> In this case, just write the same JavaScript you'd do as if you weren't
> using Tapestry.
>

 Do you mean to write a JS function and call it from the onSubmit()
function and not to use JavaScript support?.

>
>
> > When I used this line of code in the onSubmit() button function it gives
> > me  "No object of type
> > org.apache.tapestry5.services.javascript.JavaScriptSupport is available
> > from the Environment" exception!!
> >
>
> JavaScriptSupport is only available when the component is being rendered.
> Form submission is not done during rendering, so you get this exception.
>
> --
> Thiago
>
Reply | Threaded
Open this post in threaded view
|

Re: How to Show a Div using Javascript

Thiago H de Paula Figueiredo
On Mon, Oct 5, 2020 at 9:28 AM marwa hussein <[hidden email]>
wrote:

> On Mon, Oct 5, 2020, 2:22 PM Thiago H. de Paula Figueiredo <
> [hidden email]> wrote:
>
> > On Sun, Oct 4, 2020 at 8:37 AM marwa hussein <[hidden email]>
> > wrote:
> >
> > > Hi Thiago,
> > >
> >
> > Hello!
> >
> >
> > > Thanks a lot for your reply it works fine but the problem is using this
> > > line of code in beginRender() function shows the "div" when the page is
> > > loaded. but What I want is to show the div after a button is pressed.
> > >
> >
> > In this case, just write the same JavaScript you'd do as if you weren't
> > using Tapestry.
> >
>
>  Do you mean to write a JS function and call it from the onSubmit()
> function and not to use JavaScript support?.
>

No. Write it in a .js file you include in the page. That's what I meant by
writing the same JS as if you weren't using Tapestry.

--
Thiago