I have a Javascript function, which changes a text field of a form into
a select field. Following is the function
function changeStateFiel d()
{
var myForm = document.getEle mentsByTagName( "form")[0];
alert(myForm.st ateId.value);
myForm.removeCh ild(myForm.stat eId);
var stateSelect = document.create Element("select ");
stateSelect.set Attribute("stat eId2", "stateId");
myForm.insertBe fore(stateSelec t, myForm.countyId );
}
Function displays the correct value in alert. but on line 3
myForm.removeCh ild(myForm.stat eId);
it gives following error. I am using Firefox.
Error: uncaught exception: [Exception... "Node was not found" code:
"8" nsresult: "0x80530008 (NS_ERROR_DOM_N OT_FOUND_ERR)" location:
"http://localhost:8080/APP/premiseCatalog. do Line: 245"]
Your help will be greately appreciated.
Regards,
Naeem. 11 3999
Naeem wrote on 21 nov 2006 in comp.lang.javas cript:
I have a Javascript function, which changes a text field of a form into
a select field. Following is the function
function changeStateFiel d()
{
var myForm = document.getEle mentsByTagName( "form")[0];
alert(myForm.st ateId.value);
myForm.removeCh ild(myForm.stat eId);
var stateSelect = document.create Element("select ");
stateSelect.set Attribute("stat eId2", "stateId");
myForm.insertBe fore(stateSelec t, myForm.countyId );
}
Function displays the correct value in alert. but on line 3
myForm.removeCh ild(myForm.stat eId);
it gives following error. I am using Firefox.
Error: uncaught exception: [Exception... "Node was not found" code:
"8" nsresult: "0x80530008 (NS_ERROR_DOM_N OT_FOUND_ERR)" location:
"http://localhost:8080/APP/premiseCatalog. do Line: 245"]
You will have to show us the html too.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Naeem wrote:
Hi,
var myForm = document.getEle mentsByTagName( "form")[0];
document.forms[0] // simpler :)
myForm.removeCh ild(myForm.stat eId);
Function displays the correct value in alert. but on line 3
myForm.removeCh ild(myForm.stat eId);
it gives following error. I am using Firefox.
Error: uncaught exception: [Exception... "Node was not found" code:
"8" nsresult: "0x80530008 (NS_ERROR_DOM_N OT_FOUND_ERR)" location:
"http://localhost:8080/APP/premiseCatalog. do Line: 245"]
Firefox tells you that the node has not been found; as Evertjan said,
the problem lies with your HTML, the parent of your stateId element
probably being some other element than the form.
---
<head>
<script type="text/javascript">
var foo=(function() {
var cached_select=c reateElement(
"<select name='stateId'> <option value='hello'>H ello<\/select>"
);
var cached_input=cr eateElement(
"<input type='text' name='stateId'> "
);
function createElement(s tr) {
var div=document.cr eateElement("di v");
div.innerHTML=s tr;
return div.firstChild;
}
return function(form){
var el, type=form.state Id.nodeName.toL owerCase();
form.removeChil d(form.stateId) ;
switch (type) {
case "input" : el=cached_selec t; break;
case "select" : el=cached_input ; break;
}
form.insertBefo re(el,form.firs tChild);
}
})();
</script>
</head>
<body>
<form action="#">
<input type="text" name="stateId">
<input type="button" value="Toggle" onclick="foo(th is.form)">
</form>
</body>
---
Thank you for response.
Following is the code of my HTML file.
=============== =============== =============== =============== =============== ==========
<%@ taglib uri="/WEB-INF/catalog.tld" prefix="catalog " %>
<%@ taglib uri="/WEB-INF/catalog-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/c.tld" prefix="cd" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<title>Premis es </title>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
<script language="JavaS cript">
function changeStateFiel d()
{
var myForm = document.getEle mentsByTagName( "form")[0];
alert(myForm.st ateId.value);
myForm.removeCh ild(myForm.stat eId);
var stateSelect = document.create Element("select ");
stateSelect.set Attribute("stat eId2", "stateId");
myForm.insertBe fore(stateSelec t, myForm.countyId );
}
</script>
</HEAD>
<BODY >
<catalog:reco rd bean="premise">
<catalog:data >
<table width="100%" border="0" cellpadding="1" cellspacing="0"
class="grayBG">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1"
class="whiteBG" >
<tr>
<td colspan="2">
<table width="100%" height="20" border="0" cellpadding="0"
cellspacing="0" class="tablebhe ad">
<tr>
<td class="navBarBG " style="font-size: 8pt" width="33%">Pre mise
Details </td>
<td align="left" class="navBarBG " style="font-size: 8pt"
width="67%">
</td>
</tr>
</table>
</td>
</tr>
<!--Data Control s here-->
<tr class="dataEntr y">
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="1" bgcolor =
"#EBF2F8" cellspacing="2" >
<tr>
<TD class="fieldLab el" width="22%"Zip Code
<span class="ast">*</span></TD>
<td width="692"><ht ml:text property="zip"
name="premise" maxlength="5" size="20" /></td>
</tr>
<tr>
<TD class="fieldLab el" width="22%"Sele ct State
<span class="ast">*</span></TD>
<td>
<html:text property="state Id" name="premise" readonly="true"
maxlength="6" size="20" />
<input type="button" value="change"
onclick="change StateField();"/>
</td>
</tr>
<tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</table>
</catalog:data>
</catalog:record>
</html:form>
</catalog:root>
</BODY>
</HTML>
=============== =============== =============== =============== =============== ==========
Following is the FORM and TEXT tags from catalog-html.tld
FORM TAG
=============== ==
<name>form</name>
<tagclass>com.m ycompany.datagr id.taglib.html. FormTag</tagclass>
<bodycontent>JS P</bodycontent>
<attribute>
<name>action</name>
<required>tru e</required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>enctype </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onKeyUp </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onClick </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>focus</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>focusInde x</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>method</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onreset </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onsubmi t</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>style</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>styleClas s</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>styleId </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>target</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>type</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
</tag>
<tag>
=============== =============== =============== =============== =============== ==========
TEXT
=============== =============== =============== =============== =============== ==========
<name>text</name>
<tagclass>com.m ycompany.datagr id.taglib.html. TextTag</tagclass>
<attribute>
<name>accesskey </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>alt</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>altKey</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>disable d</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>indexed </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>maxlength </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onblur</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onchang e</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onclick </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>ondblclic k</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onfocus </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onkeydown </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onkeypres s</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onkeyup </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onmousedo wn</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onmousemo ve</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onmouseou t</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onmouseov er</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>onmouseup </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>propert y</name>
<required>tru e</required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>readonl y</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>size</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>style</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>styleClas s</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>styleId </name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>tabinde x</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>title</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>titleKe y</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>false </required>
<rtexprvalue>tr ue</rtexprvalue>
</attribute>
</tag>
Naeem wrote:
Thank you for response.
Following is the code of my HTML file.
What's that soup? What we meant was the processed HTML page (which you
can get using view-source), not the one to be generated using server
components - I don't even see the start FORM tag :)
Make sure your form is correctly built, that the elements have received
correct names; then it should go smoothly.
Anyway, you seem to have in mind the FORM hierarchy when calling DOM
methods. This is not the way it works, DOM methods work with nodes, in
your case the parent node of your (missing) input field would be the TD,
not the FORM.
Instead of
myForm.removeCh ild(myForm.stat eId);
simply try
myForm.stateId. parentNode.remo veChild(myForm. stateId);
Note that other DOM methods (insertBefore, appendChild) work with DOM
nodes as well, so you must identify the appropriate nodes on which the
DOM operation shall be performed, prior to the actual performing.
HTH.
Naeem a écrit :
Thank you for response.
Following is the code of my HTML file.
No no no thank you ! keep it by you !
I tested your function in a very simple context and yes :
uncaught exception: [Exception... "Node was not found"
.... nothing to do : error
As it would be impossible to remove an input ... :-(
But to remove the P containing the input it's OK !
function changeStateFiel d(what){
var myForm = document.forms[0];
var target = document.getEle mentById('count yId');
var stateSelect = document.create Element("select ");
var s = myForm.stateId. value;
var o = new Option(s,s);
stateSelect.opt ions[stateSelect.len gth] = o;
stateSelect.set Attribute("id", "stateId2") ;
myForm.insertBe fore(stateSelec t,target);
alert(myForm.st ateId.value); // see the new select and old input
myForm.removeCh ild(target);
}
<form>
<h2>title</h2>
<p id="countyId">
<input name="stateId" id="stateId" type=text value="123" />
<a href="#" onclick="change StateField();re turn false;">select</a>
</p>
</form>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Elegie a écrit :
>
Anyway, you seem to have in mind the FORM hierarchy when calling DOM
methods. This is not the way it works, DOM methods work with nodes,
Instead of
myForm.removeCh ild(myForm.stat eId);
simply try
myForm.stateId. parentNode.remo veChild(myForm. stateId);
I really don't understand.
Say :
<form>
<input name="stateId" id="stateId" type=text value="123" />
<p id="countyId">
<a href="#" onclick="change StateField();re turn false;">select</a>
</p>
</form>
I think element input 'stateId' is a direct child of the form.
With myForm = document.forms[0]
Why
myForm.removeCh ild(myForm.stat eId);
gives an error
while
myForm.stateId. parentNode.remo veChild(myForm. stateId);
works fine ?
In other words, why 'myForm.stateId ' could be seen as a DOM node
and not 'myForm' for which we have to use 'myForm.stateId .parentNode' ?
Or does the DOM believes stateId is in a P (even if it isn't coded) ?
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
ASM wrote:
Hey,
Say :
<form>
<input name="stateId" id="stateId" type=text value="123" />
<p id="countyId">
<a href="#" onclick="change StateField();re turn false;">select</a>
</p>
</form>
I think element input 'stateId' is a direct child of the form.
That is indeed what one might think as first, however... the way FORM
and FORM elements are created by user agents have been demonstrated to
be quite 'unexpected' when the HTML is malformed :p
In this example, not providing explicit BODY tags makes IE (and probably
other browsers) believe the INPUT element is child of the BODY, not of
the FORM.
In other words, why 'myForm.stateId ' could be seen as a DOM node
and not 'myForm' for which we have to use 'myForm.stateId .parentNode' ?
Incorrect hypothesis, don't doubt the holy DOM !
Or does the DOM believes stateId is in a P (even if it isn't coded) ?
You were not far, however alerting myForm.stateId. parentNode.node Name
would have given you the exact answer ;)
Cheers, Elegie.
Elegie a écrit :
ASM wrote:
>> <form> <input name="stateId" id="stateId" type=text value="123" /> <p id="countyId"> <a href="#" onclick="change StateField();re turn false;">select</a> </p> </form>
Or does the DOM believes stateId is in a P (even if it isn't coded) ?
You were not far, however alerting myForm.stateId. parentNode.node Name
would have given you the exact answer ;)
done
it's a P
if we can no more believe what we read !
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
ASM wrote:
done
it's a P
if we can no more believe what we read !
Nope if it tells you P then it's definitely P! I get BODY on IE6 on
Windows, however other browsers on other platforms may differ. Have you
tried with a well-formed (or let us say, better-formed) HTML document?
The parent should then be FORM.
--- yields BODY on IE6, Windows ---
<form>
<input name="stateId" id="stateId" type=text value="123">
<input type="button"
value="Parent?"
onclick="alert( this.form.state Id.parentNode.n odeName)">
</form>
---
--- yields FORM on IE6, Windows ---
<body>
<form>
<input name="stateId" id="stateId" type=text value="123">
<input type="button"
value="Parent?"
onclick="alert( this.form.state Id.parentNode.n odeName)">
</form>
</body>
---
Anyway I guess you have your answer now :)
Cheers,
Elegie. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mike |
last post by:
Hello,
After trying to validate this page for a couple of days now I was
wondering if someone might be able to help me out. Below is a list of
snippets where I am having the errors.
1. Line 334, column 13: there is no attribute "SRC"
<bgsound src="C:\My Documents\zingwent.mids">
You have used the attribute named above in your document, but the document
type you are using does not support that attribute for this element. This
error is...
|
by: Mike |
last post by:
Please help this is driving me nuts. I have 2 forms, 1 user class and I am
trying to implement a singleton class. Form 1 should create a user object
and populate some properties in user. Form2 should then have access to those
user properties. I am not getting the property value from user that was set
in form1.
Sorry for posting so much code but I need help bad. How do i make this work?
Thanks
Mike
|
by: Vish |
last post by:
I am trying to use xmldatadocument to load an xml file.The xml has the data
as attributes, the datadocument is able to successfully parse the document
into the tables and shows the right column count but does not add any rows. I
tried validating the schema everything is fine but no data is returned . I
have attached the sample xml file and schema. Any help is appreciated .
Thanks!
<SiebelMessage CallingApp="COM" ErrorMsg="" ErrorCode=""...
|
by: Tim::.. |
last post by:
Can someone please help....
I'm having major issues with a user control I'm tring to create!
I an trying to execute a sub called UploadData() from a user control which I
managed to do but for some reason I keep getting the error:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
|
by: John Regan |
last post by:
Hello All
I am trying to find the owner of a file or folder on our network (Windows
2000 Server) using VB.Net and/or API. so I can search for Folders that don't
follow our company's specified folder structure and naming conventions and
then send a Net send message to those users telling them to rectify.
The information I want to get is when you select the file/folder and then:
Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
| |
by: cj |
last post by:
Lets just take this example I'm looking at now. I'm looking at the help
screen titled .NET Framework Class Library FolderBrowserDialog Class
. It gives an example at the bottom that begins with:
' The following example displays an application that provides the
ability to
' open rich text files (rtf) into the RichTextBox. The example demonstrates
' using the FolderBrowserDialog to set the default directory for opening
files.
' The...
|
by: Dennis Fazekas |
last post by:
Greetings,
I am creating a web form which will all the user to add an unlimited number
of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to
remove, and a "Save" button. When the user clicks the "Add another email" it
will call a client side JavaScript function, add_email, which will
dynamically add a new set of controls to the webpage using the innerHTML
method. It appears to work perfectly fine in the browser. The...
|
by: aljamala |
last post by:
Hi,
I keep getting this warning on a page, but I do not know what the
problem is...does anyone have an idea about what could be wrong?
line 88 column 7 - Warning: missing </formbefore <td>
it highlights this line: <form name="frmCurrency" action=""
method="post">
Page source....
|
by: forest demon |
last post by:
i'm trying to create a .xsd file to validate the XML below(just a
small snippet). i've tried a number of things and can come close, but
i can't quite get it to do what i want. i'm able to validate the
snippet below using .NET with a schema that will make sure that the
six attributes are correct in spelling, but that's about it.
i would like it to be able to:
1) make sure each element(tool) is correct by having all the six
attributes...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |