473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

DIV PROBLEM

Hi guys this is my problem :

I have created a js function where I can add fields on the fly, but
there seems to be a small flaw with Mozilla.

If you try to click on "Add" button you can see that for every click
there is a new text field and this is really useful
because I don't need to refresh the page every time. It works 100% fine
with Internet Explorer but in Mozilla it seems to loose the values
I type in in field 2 or field 3 etc.

For example, if I have 2 lines and I click to get a third one, I loose
the values in the fields in line 2, and line 1.

If I have 3 lines and want to add another one, I loose the values for
lines 2 and 3, and 1.

Again, this works fine in IE, but not in Mozilla.

Any idea how to fix this?
*this is the page *
http://dev.shipco.com/temp/div.html
*this is the code*

<form Action ="Save.php?ID=106" Name="input1" Method = Post
Onsubmit="return Checkform(this);">
<div id="prova"></div>

<table width=100% border="0" align="center" cellpadding="3"
cellspacing="1" >

<script>
function htmlwrite()
buildHTML= "<input type=text><br>"
elem = document.getElementById('prova');
elem.innerHTML = elem.innerHTML + buildHTML;

}
</script>
</TD></TR>
<tr>
<td align=center colspan=2>
<input type=button class=button name=add
onClick="javascript:htmlwrite();" value = "Add TEXT FIELD">
</td>
</tr>
<Table>

Thanks a lot guys

Andrea

Jul 20 '05 #1
2 1420
First, do not crosspost over top hierarchies. X-Post removed.

Second, do not try to arouse interest in your postings by writing the
Subject only in uppercase letters and/or with multiple sentence marks.
More people will be repelled than attracted by such a Subject header.

Third:

| [03:29:31] pointedears:~ $ host -t mx kkjkjkjij.it
| Note: nslookup is deprecated and may be removed from future releases.
| Consider using the `dig' or `host' programs instead. Run nslookup
| with the `-sil[ent]' option to prevent this message from appearing.
| Server: 62.53.246.30
| Address: 62.53.246.30#53
|
| ** server can't find kkjkjkjij.it: NXDOMAIN

By using a faked e-mail address you prevent you from getting
spam, but at the same time you help to destroy the Internet.
Due to the egotistical behavior you display with such, I will
not download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.

Andrea Gelsogroove wrote:
http://dev.shipco.com/temp/div.html
http://validator.w3.org/check?uri=ht.../temp/div.html
<form Action ="Save.php?ID=106" Name="input1" Method = Post
Onsubmit="return Checkform(this);">
<form action="Save.php?ID=106" name="input" method="post"
onsubmit="return Checkform(this);"

Watch for the case in URIs. Is the filename really `Save.php' or
is it `save.php' instead? Most servers are not using FAT or NTFS
file systems, thus filename case is important.

Watch for the case in attribute and JavaScript identifiers, too.
Lowercased identifiers are not only better compressible, they
also save you trouble in case-sensitive applications like XHTML
and JavaScript. For JavaScript, only identifiers of constructor
functions should start with an uppercase character, to avoid
confusion.
<div id="prova"></div>

<table width=100% border="0" align="center" cellpadding="3"
cellspacing="1" >

<script>
The above is all invalid HTML. Write at least

<table width="100%" border="0" align="center" cellpadding="3"
cellspacing="1">

and

<script type="text/javascript">

(But `script' *must* *not* be a child of `table', see below.)
function htmlwrite()
buildHTML= "<input type=text><br>"
´buildHTML' is unnecessarily declared global here.
Use the `var' keyword to make it a local variable.

`type="text"' is the default, you can safely omit it.
elem = document.getElementById('prova');
Again, `elem' need not and should not be declared global *in*
*general*. However, for this is a method called more than once
and operating on the same object, `elem' should be global and
hold the reference to the HTMLDivElement Object so that it
should not be retrieved every time the function is called.

But more important, document.getElementById(...) is a method
of the W3C-DOM and you do not check for support of it before
accessing it. See

http://pointedears.de.vu/scripts/test/whatami

for details.
elem.innerHTML = elem.innerHTML + buildHTML;
OTOH `innerHTML' is a proprietary property *not* part of the
W3C-DOM. Although supported in the HTML-DOM of recent user
agents, you should stick to one object model because of the
reasons mentioned in the test case document and because of the
problems that will arise otherwise if you possibly change the
DOCTYPE to XHTML.

Quickhack:

var oProva = null; // was `elem' previously
if (document.getElementById) // possibly W3C-DOM compliant
oProva = document.getElementById('prova');
else if (document.all) // possibly IE4-DOM compliant
oProva = document.all['prova'];
// Using the argument `o' for passing the reference
// makes the function more independent of the context
// it is called from.
function htmlWrite(o)
{
if (o)
{
if (document.createElement && o.appendChild)
{
var oInput = document.createElement("input");
if (oInput)
{
oInput.type = "text";
if (o.appendChild(oInput))
{
var oBr = document.createElement("br");
if (oBr)
{
o.appendChild(oBr);
}
}
}
}
else if (typeof o.innerHTML != "undefined")
{
o.innerHTML += "<input><br>\n";
}
}
}
}
</script>
</TD></TR>
That is like my recent example of how `script' elements can be misplaced
while creating invalid HTML. The `script' element must not be the child
element of the `table' element, only `tbody', `thead', `tfoot', `th' and
`td' may be. The `script' element, however, has nothing to do with the
`table' element, thus it should be the child of the `head' element so
that the function is early available.
<tr>
<td align=center colspan=2>
<input type=button class=button name=add
onClick="javascript:htmlwrite();" value = "Add TEXT FIELD">
Once you define the default scripting language standards-compliant with

<meta http-equiv="Content-Script-type" content="text/javascript">

within the `head' element you do not longer require proprietary
extensions like this. `javascript:' is basically a proprietary URI
scheme. Using it in presumed JavaScript code makes it only a label.
Only the IE browser component reads this label to define the used
scripting language, other UAs do not and will even trigger script
errors if labels are not supported (in event handlers). Write

<input type="button" name="add" value="Add TEXT FIELD" class="button"
onclick="htmlWrite(oProva);"> <!-- pass a reference as arg. -->

instead. Note that users without JavaScript cannot use that
button, so you should provide a working alternative for them.
</td>
</tr>
<Table>


The last tag should be the close tag </table>. But you will not
want nor need a table here. Never use a `table' element for layout
purposes only. A table is a table is a table [psf 3.8], and CSS
exists.
HTH

PointedEars
Jul 20 '05 #2
Thomas 'PointedEars' Lahn hu kiteb:
By using a faked e-mail address you prevent you from getting
spam, but at the same time you help to destroy the Internet.
Due to the egotistical behavior you display with such, I will
not download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.


Just out of curiousity, which do you consider more harmful to teh
Internet:

1 - An obviously invalid/munged email address.
2 - An email address which looks valid, but which is never read.

With the first, anyone who tries and has basic knowledge of the internet
would know it is invalid. With the second, they will never know, and
neither would teh intended recipient, unless they then mention it in the
newsgroup.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #3

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

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.