473,405 Members | 2,373 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,405 software developers and data experts.

get element by long name

in my jsp, there is something like:

<input type=text name"plateDetail.name" value="xxxx" />
How can I get this element in javascript? the following code does not
work:

var name = document.getElementByName("plateDetail.name").valu e;

I think it is because there is a '.' in the name.

Any idea?

Thanks,

qq

Feb 8 '06 #1
2 1352
qu******@yahoo.com wrote:
in my jsp, there is something like:

<input type=text name"plateDetail.name" value="xxxx" /> ^^^
<input type=text name="plateDetail.name" value="xxxx" />

Is this really XHTML? If not, use correct HTML tags (i.e. close the tag
with '>' not '/>').

How can I get this element in javascript? the following code does not
work:

var name = document.getElementByName("plateDetail.name").valu e; ^^^

What you are looking for is the document.getElementsByName method, note
the 's'.

It returns a collection, which is a nodeList (kind of like an array
without all the goodies like split and join) that does not have a value
property (it does have a length property).

It's also not a good idea to have a variable called 'name', since that
is also a property of the object you are getting a reference too. Call
it nameText or similar.

If there is only one element with the name 'plateDetail.name' then use:

var nameText = document.getElementsByName("plateDetail.name")[0].value;
Incidentally, you will find the forms collection more widely supported
than getElementsByName, so if the input is in a form (wrapped for posting):

var nameText =
document.forms['fName'].elements['plateDetail.name'].value;
where 'fName' is the name of the form that the input is in.

I think it is because there is a '.' in the name.


A period is perfectly OK in the value of a name attribute, is is your
invalid markup teamed with scripting errors and incorrect use of methods
that has you stymied.

--
Rob
Feb 8 '06 #2
qu******@yahoo.com wrote on 08 feb 2006 in comp.lang.javascript:
in my jsp, there is something like:
What has jsp to do with it?
<input type=text name"plateDetail.name" value="xxxx" />
Do you mean HTML?

You're missing the "=":

<input type='text' name='plateDetail.name' value='xxxx' >


How can I get this element in javascript? the following code does not
work:

var name = document.getElementByName("plateDetail.name").valu e;
Must be getElementsByName, you're missing the "s":
I think it is because there is a '.' in the name.


Not so.
Try:

============================
<input type='text' name='plateDetail.name' value='xxxx'>

<script type="text/javascript">
var myName = document.getElementsByName("plateDetail.name")[0].value;
alert(myName)
</script>
=============================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 8 '06 #3

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

Similar topics

0
by: CJ | last post by:
I started with this schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="response"> <xs:complexType> <xs:sequence> <xs:element...
1
by: Wolfgang Lipp | last post by:
my question is: do we need container elements for repeating elements in data-centric xml documents? or is it for some reason very advisable to introduce containers in xml documents even where not...
0
by: Wolfgang Lipp | last post by:
From: Lipp, Wolfgang Sent: Tuesday, 27?January?2004 13:26 <annotation> the first eleven contributions in this thread started as an off-list email discussion; i have posted them here with...
6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
6
by: Michael Hill | last post by:
I have this code that adds a table row and within the cells I create some input elements. When I go back using javascript the functionaliuty is seeing the form element. Anyone tell why I can see...
3
by: michael | last post by:
let me keep it clean, quick and simple. I am passing a variable into another window and am reassigning the value on the new page - window.document...value = opener.document. ....value and...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
1
by: IsValidUN | last post by:
How do you define an element within a schema that has an attribute For example in the following Offset has an attribute + a long value: <Cue> <Name>mycue</Name> <Offset Kind="Start">0</Offset>...
22
by: DL | last post by:
Hi, What I wanted to do is to call a function from a newly created element. But it stumbled me. Here's the line that references the newly created element and I used the alert function for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
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...

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.