473,395 Members | 1,403 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,395 software developers and data experts.

Working on forms where element names have spaces

I'm working on a web page which has some form elements in it which I need to
manipulate using JavaScript.

If the element is (for example, in a form called TicketForm)

<INPUT name="intNumTickets" onBlur="calcPrice();" value="0">

I can read and manipulate this value in CalcPrice using the format

document.TicketForm.intNumTickets

My problem is, this form needs to pass the values to a payment processor,
and they say that the name needs to be preceded with the text 'PT' so that
it is passed back to the form later without any processing (no, I cannot
change this aspect).

So the input statement would be

<INPUT name="PT intNumTickets" onBlur="calcPrice();" value="0">

....but my problem is, how do I reference PT intNumTickets using the document
format?

document.TicketForm.PT intNumTickets

won't work.

Any ideas how I can handle this?

Regards,
Pete.
Jul 23 '05 #1
7 1591
PeteC wrote:
<INPUT name="PT intNumTickets" onBlur="calcPrice();" value="0">

...but my problem is, how do I reference PT intNumTickets using the document
format?


You use the square brackets notation, i.e.
document.forms["myForm"].elements["PT intNumTickets"];

See the FAQ, especially
<URL:http://jibbering.com/faq/#FAQ4_39>
Regards,
Yep.
Jul 23 '05 #2
PeteC wrote:
<INPUT name="PT intNumTickets" onBlur="calcPrice();" value="0">
...but my problem is, how do I reference PT intNumTickets using the
document format?
document.TicketForm.PT intNumTickets
won't work. Any ideas how I can handle this?


http://jibbering.com/faq/#FAQ4_25

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #3
Hi Pete,
they say that the name needs to be preceded with the text 'PT'... [snip].. name="PT intNumTickets" ...


First of all, they said that it needed to preceded with 'PT', but did
they also say it had to have a space in between? If that is still the
case, then yes there is another way for you to reference the form
elements. Try using the following way:

document.forms[x].elements[y]

For example, let's say you have only 1 form:

<form name = "foo" action = "url" method = "post" onsubmit = "return
myFunc();">
<input name = "PT intAbc"/>
<input name = "PT intNumTickets"/>
<input name = "PT intXyz"/>
</form>

You can then go through your elements by the following:

for(var i = 0; i < 3; i++)
{
var tmp = document.forms[0].elements[i].value;
//code to do something with the value
}

Where 3 (if you know beforehand) is the number of elements in the form.

Hope this helps. :)

Jul 23 '05 #4
web.dev wrote:
Hope this helps. :)


Certainly does. Many thanks.

Pete.
Jul 23 '05 #5

Spaces are not allowed in ID/Names per standards:

HTML4.1 and CSS definition on CDATA which is what name/attributes use

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
by any number of letters, digits ([0-9]), hyphens ("-"), underscores
("_"), colons (":"), and periods (".").

and the instructions never mentioned anything about spaces, just a PT
prefix, associative naming which is used often to categorize objects.

Danny

On Tue, 12 Jul 2005 12:18:17 -0700, PeteC
<ma*************@acutecomputing.co.uk> wrote:

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #6
Zif
Danny wrote:

Spaces are not allowed in ID/Names per standards:

HTML4.1 and CSS definition on CDATA which is what name/attributes use

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").


That is *not* the specification for CDATA, it is for SGML ID and NAME
tokens (that's why it says ID and NAME tokens in the text).

The CDATA spec is:

" CDATA is a sequence of characters from the document character set and
may include character entities. User agents should interpret attribute
values as follows:

* Replace character entities with characters,
* Ignore line feeds,
* Replace each carriage return or tab with a single space.

"User agents may ignore leading and trailing white space in CDATA
attribute values (e.g., " myval " may be interpreted as "myval").
Authors should not declare attribute values with leading or trailing
white space.

"For some HTML 4 attributes with CDATA attribute values, the
specification imposes further constraints on the set of legal values
for the attribute that may not be expressed by the DTD.

"Although the STYLE and SCRIPT elements use CDATA for their data model,
for these elements, CDATA must be handled differently by user agents.
Markup and entities must be treated as raw text and passed to the
application as is. The first occurrence of the character sequence "</"
(end-tag open delimiter) is treated as terminating the end of the
element's content. In valid documents, this would be the end tag for
the element."

None of which disallows the use of spaces.
--
Zif
Jul 23 '05 #7
Danny wrote:
ID and NAME tokens


Unintuitive though it may be, form control name attributes don't take NAME
tokens for their values. Spaces are OK.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #8

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

Similar topics

6
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything...
4
by: Ragnar Heil | last post by:
This line works fine for me: Set objDOMnode = objDom.selectSingleNode("//headline") strHeadline = objDOMnode.Text Now I want to get the value from this node: <nitf> - <head> - <docdata> -...
12
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
2
by: Mark Hannon | last post by:
I am designing a PayPal shopping cart/store for a client and have placed several of PayPal's shopping cart forms on the page to correspond with different products. Each form has a unique name...
2
by: Michael Bulatovich | last post by:
I have a simple db to keep track of work/time/projects etc. It has two fields (column) named "start time" and "end time" WITH THE SPACES. I'm trying to do some automation to a form associated with...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
16
by: Frances | last post by:
<a href="#1"> <a name="#1"> this link is not working in FF (works fine in IE..) would appreciate thoughts/suggestions.. thank you.. Frances
4
by: Martínez | last post by:
Hi, Here's a scaled down version of what I'm working with. It execututes correctly in IE, but FireFox fails to run it. The JavaScript Console reports the error "Error:...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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
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...

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.