474,046 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple script does not work

Can anyone see why this simple script doesnt make the element visible? It
starts of as hidden but will not show when the button is clicked. This has
worked for me before but I cannot see what is different.

Thanks


<script language="Javas cript">
<!--
function addnewsub(){
var newsubject = document.getEle mentById('newsu b');
newsubject.styl e.display='';
}
//-->
</script>

<input name="Submit2" type="button" class="BodyText " onClick="addnew sub()"
value="New">

here is the relevent code from table

<tr id="newsub" style="display: none;" class="DynamicF orms">
<td>&nbsp;</td>
<td>Type Subject </td>
<td>&nbsp;</td>
<td colspan="2"><in put name="textfield " type="text"
class="BodyText ">
<input name="addnewsub " type="submit" class="BodyText "
value="Add"></td>
</tr>
Sep 25 '06 #1
12 1444
mantrid wrote:
Can anyone see why this simple script doesnt make the element visible?
You're missing the table tag... Getting the habit of working with valid,
nice, beautiful and even sexy HTML will make your scripting adventure
far more enjoyable than usual - give it a try ;)
Sep 25 '06 #2

mantrid wrote:
Can anyone see why this simple script doesnt make the element visible?
newsubject.styl e.display='';
Try setting the display property to an explicit value, such as "block"
or "inline."

There is a list of properties for display, here
http://www.w3schools.com/css/pr_class_display.asp

IIRC just unsetting an element's property, as you have done, will cause
the property to be inherited from higher up in the scope chain.

Sep 25 '06 #3

"Elegie" <el****@invalid .comwrote in message
news:45******** *************** @news.free.fr.. .
mantrid wrote:
Can anyone see why this simple script doesnt make the element visible?

You're missing the table tag... Getting the habit of working with valid,
nice, beautiful and even sexy HTML will make your scripting adventure
far more enjoyable than usual - give it a try ;)
i just left that out as the table is large. just wanted to show the relevant
snippet
Sep 25 '06 #4

"Noah Sussman" <bl******@gmail .comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
>
mantrid wrote:
Can anyone see why this simple script doesnt make the element visible?
newsubject.styl e.display='';

Try setting the display property to an explicit value, such as "block"
or "inline."

There is a list of properties for display, here
http://www.w3schools.com/css/pr_class_display.asp

IIRC just unsetting an element's property, as you have done, will cause
the property to be inherited from higher up in the scope chain.

tried block. but unfortunately didnt work
Sep 25 '06 #5
mantrid wrote:
>>Can anyone see why this simple script doesnt make the element visible?
>You're missing the table tag... Getting the habit of working with valid,
nice, beautiful and even sexy HTML will make your scripting adventure
far more enjoyable than usual - give it a try ;)
i just left that out as the table is large. just wanted to show the relevant
snippet
Yes, but if you just add the <TABLEtag to your posted snippet, then it
works... so the mystery lies elsewhere, in the code you've *not* posted,
and most probably in your HTML structure, I believe.

HTH.
Sep 25 '06 #6
mantrid wrote:

[snip]

Unrelated, but...
<script language="Javas cript">
The language attribute has been deprecated for many years. Use the type
attribute, instead:

<script type="text/javascript">
<!--
The practice of "script hiding" is no longer necessary. Omit the comment
delimiters.
function addnewsub(){
var newsubject = document.getEle mentById('newsu b');
newsubject.styl e.display='';
}
I hope that you normally feature detect before using DOM methods and
object, and that this is just a simplification.
<input name="Submit2" type="button" class="BodyText " onClick="addnew sub()"
value="New">
Keep in mind the value of that onclick attribute, for a moment.
<tr id="newsub" style="display: none;" class="DynamicF orms">
Ideally, you would not hide content using a CSS declaration that you
later intend to show via scripting. Instead, using scripting to both
hide and show the element. That way, if scripting is disabled, the
content is still accessible.

[snip]
<input name="addnewsub " ...>
Notice that this form control has the same name as the function you are
trying to call, above. In some browsers, the form element is added to
the scope chain of form control event listeners. As form elements are
also usually properties of form elements (a mistake, in my opinion),
both these and properties of the form will be exposed. That is, the
identifier, addnewsub, is resolved as the form control with that name,
so "calling" this is a syntax error. Rename your form control or the
function.

Mike
Sep 25 '06 #7
Noah Sussman wrote:
mantrid wrote:
[snip]
>newsubject.sty le.display='';

Try setting the display property to an explicit value, such as "block"
or "inline."
The problem with that suggestion is that the target element is a table
row. In decent browsers, the appropriate display value is 'table-row'.
In lesser ones (like MSIE), the value used is 'block'. The two have
different rendering characteristics , and are not compatible.
There is a list of properties for display, here
http://www.w3schools.com/css/pr_class_display.asp
There is also a list in the various CSS Recommendations , which should be
the primary reference material.
IIRC just unsetting an element's property, as you have done, will cause
the property to be inherited from higher up in the scope chain.
Be careful when using the word "inherit" with CSS: it has a specific
meaning. The correct term here is "the cascade".

You are correct: assigning an empty string to a property of the style
object effectively removes that in-line style declaration. As in-line
styles have the highest specificity, they always take precedence over
other rules in the cascade. Once removed, the most specific rule in the
default, user, or author style sheets will be used instead. In this
instance, this should be fine as the OP has given no indication that
another style sheet rule attempts to hide the element, so removing the
declaration applied via the style attribute would revert to the default
style sheet value.

Mike
Sep 25 '06 #8
Thanks for the feedback everyone

I changed the function to

function addnewsub(){
document.getEle mentById("newsu b").style.displ ay = '';
}

Simply by not using a variable it now works. If anyone knows why this
happened please let me know


"mantrid" <ia********@vir gin.netwrote in message
news:wZ******** ***********@new sfe4-gui.ntli.net...
Can anyone see why this simple script doesnt make the element visible? It
starts of as hidden but will not show when the button is clicked. This has
worked for me before but I cannot see what is different.

Thanks


<script language="Javas cript">
<!--
function addnewsub(){
var newsubject = document.getEle mentById('newsu b');
newsubject.styl e.display='';
}
//-->
</script>

<input name="Submit2" type="button" class="BodyText " onClick="addnew sub()"
value="New">

here is the relevent code from table

<tr id="newsub" style="display: none;" class="DynamicF orms">
<td>&nbsp;</td>
<td>Type Subject </td>
<td>&nbsp;</td>
<td colspan="2"><in put name="textfield " type="text"
class="BodyText ">
<input name="addnewsub " type="submit" class="BodyText "
value="Add"></td>
</tr>


Sep 25 '06 #9
ASM
mantrid a écrit :
Can anyone see why this simple script doesnt make the element visible? It
starts of as hidden but will not show when the button is clicked. This has
worked for me before but I cannot see what is different.
because before you did not start with a display style

Do that :

<script language="Javas cript">
<!--
function addnewsub(){
var newsubject = document.getEle mentById('newsu b').style;
newsubject.disp lay = newsubject.disp lay==''? 'none' : '';
}
onload = addnewsub; // to undisplay your element
//-->
</script>

addnewsub() will switch your table alternatively from display to non display

--
ASM
Sep 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3266
by: Preston Crawford | last post by:
I'm looking to quickly get a photo album online. Very simple, thumbnails, a few pages, maybe a description, but hopefully a small script that's easy to edit and work into my existing site. I know about hot scripts, etc. but I was wondering if any one could recommend one? Secondly, I also want to setup a journal. It's not really a "blog" although I guess blog software may work. But it isn't going to be a message board or anything like...
6
7800
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the email posts and been advised to use the email Module and mailbox Module. The blurb from a memeber of this list . Im not at work at the moment So I cant test this out , but if someone could take a look and check that im on the write track as this...
3
4400
by: Fabrice Cavarretta | last post by:
I am using a specialized database software (for bibliography: EndNote) that does export in XML. I would like to be able to read that into a simple software, like Excel or Access, in order to do manipulation of the data (that are not allowed in EndNote). Anyone knows a simple tool (utility) that would allow that. By the way, I'm using Office 2002 (not XP/2003, which may have native XML features!).
1
8305
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two dropdown lists. If you change the selection of the left one (e.g. choose parentoption2), it should open up page2.htm in a popup window.
0
1910
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I have run into is that the emitted html at the end of the process is slightly different and doesn't work. Please don't be put off by all the source code. All the guts are in this first base class, and it doesn't do much. The rest is trivial...
73
4729
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an endless loop in a line with: if a==b: print 'OK' I mean, it would be of much help to me on my way to understanding Python to know how such prefix code leading to an endless loop can look like and if it is eventually not possible to write such...
7
1672
by: db | last post by:
Hi@all Just got a comparison problem with javascript. I want to compare : document.getElementById(currentID).getAttribute("style") with a string, e.g: "background-color: lightgreen;" They are exactly the same, but the execution result seems they are not equal. It works with firefox, but not with IE.
5
1729
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to insert a weight converter into my survey. Unfortunately this script works fine in firefox v.2 but does not cooperate with the surveymonkey software when used with internet explorer v.6. Can someone explain to me in simple terms why the script...
2
2056
by: astrogirl77 | last post by:
Hi, I'm new to Python and am hoping to find help with coding a Python script, applet. I code in an old version of Visual Basic 4.0, I have a simple app that is about 3 and a half pages of code long it does some relatively simple math additions and subtractions The problem I have is that some numbers get to be very large integers and VB automatically converts this to scientifc notation, what I need is to have all numbers added and...
7
2463
by: freddukes | last post by:
Okay... So this is my first project and I want to be able to make a tool tip appear with the basket contents whenever you hover over a link using the onmousehover='javascriptFunction()'. I have acquried (and modified) some javascript code, but it did not work... So I attempted to create a simple alert() function to test and that did not work either... This is my test codee: // tooltip.js function displayAlert() { alert("Test...
0
12142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11604
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6654
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5420
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3973
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.