By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Why doesn't this work?! Help!

P: n/a
Can anyone please tell me why this doesn't work?

The sign changes when I hit the button, and I get no error messages, but the
textarea doesn't disappear/reappear.

<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script type=text/javascript>
function openNotepad(valu){
if (valu == "+"){
document.getElementById("NP1").style.visibility="v isible";
document.form.B1.value="-"
}
else {
document.getElementById("NP1").style.visibility="h idden";
document.form.B1.value="+"
}
}
</script>

<form name="form">
<table>
<tr>
<td>
<input name=B1 type=button value=- onclick=openNotepad(this.value)>
</td>
</tr>
<div id="NP1">
<tr>
<td>
<textarea name="texta01" rows=3 cols=40></textarea>
</td>
</tr>
</div>
</table>
</form>
</body>
</html>

Thanks!

iv**@tda.no
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Iver Erling Årva" wrote:
Can anyone please tell me why this doesn't work?

The sign changes when I hit the button, and I get no error messages, but the
textarea doesn't disappear/reappear.

<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script type=text/javascript>
function openNotepad(valu){
if (valu == "+"){
document.getElementById("NP1").style.visibility="v isible";
document.form.B1.value="-"
}
else {
document.getElementById("NP1").style.visibility="h idden";
document.form.B1.value="+"
}
}
</script>

<form name="form">
<table>
<tr>
<td>
<input name=B1 type=button value=- onclick=openNotepad(this.value)>
</td>
</tr>
<div id="NP1">
<tr>
<td>
<textarea name="texta01" rows=3 cols=40></textarea>
</td>
</tr>
</div>
</table>
</form>
</body>
</html>

Thanks!

iv**@tda.no


<tr></tr> can't be inside a <div>. The only tags that should appear in
<table></table> are <thead></thead>, <tbody></tbody>, <tfoot></tfoot> and
<tr></tr>.

<tr>
<td><div id="NP1"><textarea name="texta01" ...></textarea></div></td>
</tr>

But you don't need the <div> at all:

function openNotepad(btn) {
var valu = btn.value;
var f = btn.form;
var ta = f.elements['texta01'];

if (ta && ta.style) {

if (valu == "+") {
ta.style.visibility = 'visible';
btn.value = "-";
} else {
ta.style.visibility = 'hidden';
btn.value = "+";
}
}
}

<input type="button" value="-" onclick="openNotepad(this);">

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2

P: n/a
Ok, thanks! This was just an example. What I really want is to hide and
display entire sections of code. Do I have to enclose the <DIV> tags around
each and every control to achieve that? I have a bit of code I use to hide
the contents of a form until all the dropdowns etc.i.e. the entire page has
been loaded. It is the first statement after the body- and headline tags,
and I then have a function call in the <BODY ONLOAD statement to call a
function that svitches the page contents to visible again. I use this in a
lot of my forms.

<BODY onLoad="setVisible();">

<!-- Page
headline -------------------------------------------------------------------
------------->
<H1 ALIGN="CENTER">ShipAgency - Country Maintenance</H1>

<!-- Use DIV to hide form while loading-->
<DIV ID='MyID' style='visibility:hidden'>

<FORM NAME="form" >
<CENTER>
<TABLE CELLPADDING="2">
<TR>
<TD><SPAN TITLE="Enter a code and hit the <TAB>-key">
<DIV ALIGN="RIGHT"><font size="2">*Country Code:</font></DIV>
</TD>
<td>
and the rest of the form etc.
....
until the end of the page:

</TABLE>
</CENTER>
</FORM>
</DIV>
</BODY>
</HTML>

and then the setVisible function (which is held in the page's <HEAD>
section::

function setVisible()
{
document.getElementById("MyID").style.visibility = "visible";
}

Now, the strange thing is that this works just fine with <TR>s, <TD>s and
whatever I put in there. That is why I didn't understand why the other
example didn't work (and still don't really) (or alternatively don't
understant why the above sample work...).

Confusing!

IV**@tda.no
"Grant Wagner" <gw*****@agricoreunited.com> skrev i melding
news:40***************@agricoreunited.com...
"Iver Erling Årva" wrote:
Can anyone please tell me why this doesn't work?

The sign changes when I hit the button, and I get no error messages, but the textarea doesn't disappear/reappear.

<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script type=text/javascript>
function openNotepad(valu){
if (valu == "+"){
document.getElementById("NP1").style.visibility="v isible";
document.form.B1.value="-"
}
else {
document.getElementById("NP1").style.visibility="h idden";
document.form.B1.value="+"
}
}
</script>

<form name="form">
<table>
<tr>
<td>
<input name=B1 type=button value=- onclick=openNotepad(this.value)> </td>
</tr>
<div id="NP1">
<tr>
<td>
<textarea name="texta01" rows=3 cols=40></textarea>
</td>
</tr>
</div>
</table>
</form>
</body>
</html>

Thanks!

iv**@tda.no
<tr></tr> can't be inside a <div>. The only tags that should appear in
<table></table> are <thead></thead>, <tbody></tbody>, <tfoot></tfoot> and
<tr></tr>.

<tr>
<td><div id="NP1"><textarea name="texta01" ...></textarea></div></td>
</tr>

But you don't need the <div> at all:

function openNotepad(btn) {
var valu = btn.value;
var f = btn.form;
var ta = f.elements['texta01'];

if (ta && ta.style) {

if (valu == "+") {
ta.style.visibility = 'visible';
btn.value = "-";
} else {
ta.style.visibility = 'hidden';
btn.value = "+";
}
}
}

<input type="button" value="-" onclick="openNotepad(this);">

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*

http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html

Jul 23 '05 #3

P: n/a
"Iver Erling Årva" <iv**@tda.no> wrote in message news:<40********@news.broadpark.no>...
Can anyone please tell me why this doesn't work?

The sign changes when I hit the button, and I get no error messages, but the
textarea doesn't disappear/reappear.

<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script type=text/javascript>
function openNotepad(valu){
if (valu == "+"){
document.getElementById("NP1").style.visibility="v isible";
document.form.B1.value="-"
}
else {
document.getElementById("NP1").style.visibility="h idden";
document.form.B1.value="+"
}
}
</script>

<form name="form">
<table>
<tr>
<td>
<input name=B1 type=button value=- onclick=openNotepad(this.value)>
</td>
</tr>
<div id="NP1">
<tr>
<td>
<textarea name="texta01" rows=3 cols=40></textarea>
</td>
</tr>
</div>
</table>
</form>
</body>
</html>

Thanks!

iv**@tda.no


If you name the <TD> element "NP1", instead of the <div> element,
it works... I've experienced troubles sometimes putting <DIV> or
<SPAN> elements in tables.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.