Quantcast

[S2]Using javascript to hide a struts tag

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[S2]Using javascript to hide a struts tag

Justin Frost
I want to be able to hide an entire <s:div> tag based on an onclick event from a <s:checkbox>

I was not able to hide the div.
And when I tried to hide just a <s:textbox> field only the html text box was hidden, not the label.

Anyone have any suggestions for me.

Here is what I have:  The clickProd is fired from clicking a textbox that I haven't shown in my example.

<script type="text/javascript"> function clickProd() { document.LocationAddNode.elements("prodIp").style.display = 'none'; //Only removes textbox, not the label document.LocationAddNode.elements("prodIpPort").style.display = 'none'; //Does not work } </script>

                <s:form action="LocationAddNode" validate="false" id="LocationAddNode" name="LocationAddNode">
                        <s:div id="prodIpPort" name="prodOpenLinkUri">
                                <s:textfield name="prodSendUri.ip" label="OpenLink IP" id="prodIp" />
                                <s:textfield name="prodSendUri.port" label="Port" id="prodPort" maxlength="10"/>
                        </s:div>
                 </s:form>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2]Using javascript to hide a struts tag

Maxx-10
Of course the label can't be hidden as it's not the same element.
It may also depend on the theme you're using. By default it's the
xhtml one, and as this theme creates additional <tr><td> stuff around
(which is really annoying and shouldn't be default IMHO), what you're
doing is only hiding the inner stuff in the table.

> document.LocationAddNode.elements("prodIpPort").style.display = 'none'; //Does not work
are you sure this expression matches your div...?
I don't think so, and as you're using old-style-IE-javascript, I can
only advise you to use something like this :
> document.getElementById("prodIpPort").style.display = "none";

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2]Using javascript to hide a struts tag

newton.dave
In reply to this post by Justin Frost
--- Justin Frost <[hidden email]> wrote:
> I want to be able to hide an entire <s:div> tag based on an onclick event
> from a <s:checkbox>
>
> I was not able to hide the div.

> And when I tried to hide just a <s:textbox> field only the html text box
> was hidden, not the label.

That's because the ID is for the textbox (which makes sense). It might make
sense to generate an ID for the <tr...> containing the label and input
element, though--added to my list.

> document.LocationAddNode.elements("prodIpPort").style.display = 'none';
> //Does not work

This syntax doesn't work in FF (at least on my Mac). Do you get JavaScript
errors? What browser? How are you debugging?

Why wouldn't you just use document.getElementByd("prodIpPort")? (Or use a
JavaScript library that makes things even easier?)

> <s:form action="LocationAddNode" validate="false" id="LocationAddNode"
> name="LocationAddNode">
> <s:div id="prodIpPort" name="prodOpenLinkUri">
> <s:textfield name="prodSendUri.ip" label="OpenLink IP" id="prodIp" />
> <s:textfield name="prodSendUri.port" label="Port" id="prodPort"
> maxlength="10"/>
>                         </s:div>
>                  </s:form>

I'm not sure if that will generate valid HTML; can you wrap <tr...> elements
in a <div...>? You'd probably need to hide each row rather than wrapping them
in a <div...>, but I'm never sure what's legal HTML anymore.

I'm also not sure if I'd bother using <s:div...> if you're just using it to
create a normal <div...> element; seems like unnecessary overhead.

d.



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2]Using javascript to hide a struts tag

 that has the label and field?

I'm out of my knowledge area with this one.


newton.dave wrote
--- Justin Frost <justin.frost@siemens.com> wrote:
> I want to be able to hide an entire <s:div> tag based on an onclick event
> from a <s:checkbox>
>
> I was not able to hide the div.

> And when I tried to hide just a <s:textbox> field only the html text box
> was hidden, not the label.

That's because the ID is for the textbox (which makes sense). It might make
sense to generate an ID for the <tr...> containing the label and input
element, though--added to my list.

> document.LocationAddNode.elements("prodIpPort").style.display = 'none';
> //Does not work

This syntax doesn't work in FF (at least on my Mac). Do you get JavaScript
errors? What browser? How are you debugging?

Why wouldn't you just use document.getElementByd("prodIpPort")? (Or use a
JavaScript library that makes things even easier?)

> <s:form action="LocationAddNode" validate="false" id="LocationAddNode"
> name="LocationAddNode">
> <s:div id="prodIpPort" name="prodOpenLinkUri">
> <s:textfield name="prodSendUri.ip" label="OpenLink IP" id="prodIp" />
> <s:textfield name="prodSendUri.port" label="Port" id="prodPort"
> maxlength="10"/>
>                         </s:div>
>                  </s:form>

I'm not sure if that will generate valid HTML; can you wrap <tr...> elements
in a <div...>? You'd probably need to hide each row rather than wrapping them
in a <div...>, but I'm never sure what's legal HTML anymore.

I'm also not sure if I'd bother using <s:div...> if you're just using it to
create a normal <div...> element; seems like unnecessary overhead.

d.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Justin Frost
OK seeing how I can not wrap <s:textfiled> tags in a <div>, how would I go about using the default theme to remove the whole
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2]Using javascript to hide a struts tag

newton.dave
--- Justin Frost <[hidden email]> wrote:
> OK seeing how I can not wrap <s:textfiled> tags in a <div>, how would I go
> about using the default theme to remove the whole <tr> that has the label
> and field?
>
> I'm out of my knowledge area with this one.

There are several ways around this issue, each having tradeoffs and
compromises. Using the "simple" theme means you don't get the automagic error
messages, but you can make your on <tr> elements, apply a CSS classname, and
hide each <tr> that you don't want to see (as opposed to hiding a single
<div> you hide multiple <tr>s.)

Creating or modifying a theme is more work, but is ultimately the more robust
solution.

d.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...