473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Just for a change... this doesn't work in IE .. but does in Mozilla!

Hi,

Code below dynamically adds an input box to a form, creating a new name
attribute as it goes... (many thanks to Martin Honnen for getting me this
far ;0) Problem is - in IE5.5 only the first form field (the hard-coded one)
is recovered from the form, while with Mozilla/Firefox all fields are.

The alert() just shows that the newly created element has no name in IE. Can
anyone offer help with this bizarre problem (I thought any old rubbish would
run in IE - even mine!)

Regards
Rae MacLeman
----------------------------------------------------------------------------
---------

<HTML>
<HEAD>
</HEAD>
<SCRIPT LANG=Javascript >
<!--
var gCount=1;
function DoChange() {
var objNewName, objBR;
gCount++;
objNewName = document.create Element('INPUT' );
objNewName.setA ttribute('NAME' , 'fname'+gCount) ;
alert('object name = '+objNewName.na me);
objNewName.setA ttribute('ID', 'name'+gCount);
objBR = document.create Element('BR');
document.getEle mentById("names ").appendChild( objNewName);
document.getEle mentById("names ").appendChild( objBR);
delete objNewName;
delete objBR;
}
//-->
</SCRIPT>

<BODY>
<form action="mozilla _test2_handler. asp" method="POST">
<div id="names" name="names">
<input id="fname1" name="fname1" type="text"><br >
</div>
<INPUT TYPE=button ONCLICK=DoChang e() VALUE='Add name'><input
type="submit"></form>
</BODY>
</HTML>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04
Jul 23 '05 #1
3 1323
On Sun, 10 Oct 2004 07:50:21 +0100, webdev <so*****@micros ofdt.com> wrote:

[snip]
<HEAD>
Valid documents require a TITLE element to be present.
</HEAD>
<SCRIPT LANG=Javascript >
There is no such thing as a lang attribute. You intended language, but
even that should be avoided as it has been deprecated in favour of the
(required) type attribute.

<script type="text/javascript">
<!--
Hiding scripts is an obsolete practice. All browsers in use understand the
SCRIPT element, even if they can't execute scripts.
var gCount=1;
function DoChange() {
var objNewName, objBR;
gCount++;
objNewName = document.create Element('INPUT' );
objNewName.setA ttribute('NAME' , 'fname'+gCount) ;
alert('object name = '+objNewName.na me);
objNewName.setA ttribute('ID', 'name'+gCount);
Don't use the setAttribute method with HTML documents. Instead, use the
relevant properties.

objNewName.name = 'fname' + gCount;
objNewName.id = 'name' + gCount;
objBR = document.create Element('BR');
document.getEle mentById("names ").appendChild( objNewName);
document.getEle mentById("names ").appendChild( objBR);
Instead of calling getElementById twice, consider saving the reference
returned by the first call and use it twice.
delete objNewName;
delete objBR;
You cannot delete local variables. It won't cause an error, but it doesn't
do anything, either. You can see this by looking at the return value of
the delete operator. If the property being deleted doesn't exist, or it
does and has been deleted, the delete operator returns true. If the
property cannot be deleted, the operator returns false.

// In a function
var test = {};
alert(test); // alerts [object Object]
alert(delete test); // alerts false
alert(test); // alerts [object Object]

Even if you could delete a local variable, there's no point. When the
function returns, local variables are destroyed[1] and any objects will
have their reference counts decremented.

[snip]
<div id="names" name="names">
DIV elements do not have a name attribute.

[snip]
<INPUT TYPE=button ONCLICK=DoChang e() VALUE='Add name'>


You need to quote that onclick attribute value.

... onclick="DoChan ge()" ...

[snip]

Hope that helps,
Mike
[1] Obviously, a closure will stop this, but that doesn't occur here. If
it did, assign null to the variables to explicitly remove the references.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:opsfnewutt x13kvk@atlantis ...
On Sun, 10 Oct 2004 07:50:21 +0100, webdev <so*****@micros ofdt.com> wrote:

[snip]
<HEAD>


Valid documents require a TITLE element to be present.
</HEAD>

[SHORTENED}

Many thanks for that.

Rae MacLeman


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04
Jul 23 '05 #3
On Sun, 10 Oct 2004 09:48:31 GMT, Michael Winter
<M.******@bluey onder.co.invali d> wrote:
On Sun, 10 Oct 2004 07:50:21 +0100, webdev <so*****@micros ofdt.com>
wrote:


[snip]
<SCRIPT LANG=Javascript >


There is no such thing as a lang attribute.


Before anyone comments on that potentially misleading statement, I'll
rephrase it.

The lang attribute does exist as part of the internationalis ation (i18n)
attribute set, however it is not applicable to SCRIPT elements. It
specifies a two character language code[1], along with another optional
subset code separated by a dash (-), specifying the language used as
content in the relevant element.

For example, to indicate that an entire document is written in English,
you can specify:

<html lang="en">

Whereas

<img lang="fr" alt="Voici Fabienne, mon &eacute;pous e."
src="fabienne.j pg">

indicates that the alt text is French.

[snip]

Mike
[1] Language codes specified in ISO 639, and the accompanying subset
codes, are usually two characters. However, they can be anything from one
to eight characters in length. Some registered examples of this include
i-klingon and en-scouse.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4

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

Similar topics

1
8988
by: Mr. x | last post by:
Hello, Suppose I have a table like this : <table width = "580"> <tr align = "right" width = 760> <td id = "current_page_inner"> <font size="4" color="lightgreen" face="arial"><b><i> abc </i></b>
9
2285
by: Nick | last post by:
I have the following code, and it works well on Mozilla 1.6. (However, the image src property cannot be set on Mozilla 1.2.1). Unfortunately, all the code: document.images.itemImage.src = itemInfo.imageUrl; //document.getElementById("itemImage").src = itemInfo.imageUrl; document.getElementById("descr").innerHTML = itemInfo.descr; document.getElementById("price").innerHTML = itemInfo.price; doesn't work on IE. What's the proper way to...
40
3116
by: komone | last post by:
"Now is the time for all good web developers to use stylesheets". Hmm OK, so I start this commercial site design with the express intent of using CSS entirely. (Something I haven't attempted in about 3 years since I last wasted my time trying to get it to work). The site layout is intended to look (nearly precisely) like this from the CSS-2 spec: http://www.w3.org/TR/REC-CSS2/visuren.html#fixed-positioning
2
2416
by: kelvin | last post by:
Hi, I've this piece of code which does not work at all. Can anyone point out my mistake? I've 2 buttons. History button will call verifyFields() function and lead to different page for processing. verifyFields() is working fine and so does the history() function.
3
25315
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and readOnly attribute. For example, #1 will work, but #2 doesn't work 1) <SELECT name="streetDirection" class="FormInput" DISABLED> In JavaScript, I have InputForm.streetDirection.disabled = false; 2) <SELECT name="streetDirection" class="FormInput"...
5
27018
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for changing the text color. I can set style.background='red' to change the background color to red. But if I say style.color='green' to change the text color, it does not change. How do you change the text color on a button when it is clicked?
3
6760
by: Fluffy Convict | last post by:
I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does not listen to the textarea.wrap = 'soft' command. Because I want the script to be cross-browser compatible, someone suggested to remove and immediately add a node to the DOM, so I now have: ...
6
4738
by: Stefan Mueller | last post by:
With document.body.style.cursor = "wait"; I can set the hourglass and with document.body.style.cursor = "default"; I can set the MousePointer back. That works great. But if I do document.body.style.cursor = "wait"; <sort the table> document.body.style.cursor = "default";
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
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
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
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
6521
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
5860
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
4370
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
3050
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
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.