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

javascript and form names

dan
I have a script that selects a value in an option in a selection list
according to how many letters were entered in an input box. I have it
working but I am limited to what I can name the form fields because
they are dynamically created by a PHP script.

I can get it to work with simple name but not with names outputted by
the script. Is there a change I can make to the JavaScript so I can
use the dynamic names?

Simple name = 'letter_number'
Dynamic name = 'id[txt_3]'

-----------------------------
EX w/ simple input names
WORKING:
<form action="#" name="form_name">
Text Insert:
<input type="text" name ="text_name" size="6" maxlength="6" value=""
onChange="document.form_name.letter_number.value=d ocument.form_name.text_name.value.length+6;"
onBlur="document.form_name.letter_number.value=doc ument.form_name.text_name.value.length+6;">
<br>
# of letters:
<select name="letter_number">
<option value="7">1</option>
<option value="8">2</option>
<option value="9">3 (+$4.00)</option>
<option value="10">4 (+$8.00)</option>
<option value="11">5 (+$12.00)</option>
<option value="12">6 (+$16.00)</option>
</select>
</form>

---------------------------
w/ outputted dynamic names (just need to get it working with this type
of name)
NON WORKING:
<form action="#" name="form_name">
Text Insert:
<input type="text" name ="id[txt_3]" size="6" maxlength="6" value=""
onChange="document.form_name.id[5].value=document.form_name.id[txt_3].value.length+6;"
onBlur="document.form_name.id[5].value=document.form_name.id[txt_3].value.length+6;">
<br>
# of letters:
<select name="id[5]">
<option value="7">1</option>
<option value="8">2</option>
<option value="9">3 (+$4.00)</option>
<option value="10">4 (+$8.00)</option>
<option value="11">5 (+$12.00)</option>
<option value="12">6 (+$16.00)</option>
</select>
</form>
Jul 20 '05 #1
10 2922
Lee
dan said:

I have a script that selects a value in an option in a selection list
according to how many letters were entered in an input box. I have it
working but I am limited to what I can name the form fields because
they are dynamically created by a PHP script.

I can get it to work with simple name but not with names outputted by
the script. Is there a change I can make to the JavaScript so I can
use the dynamic names?

Simple name = 'letter_number'
Dynamic name = 'id[txt_3]'


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

Jul 20 '05 #2
dan
Lee <RE**************@cox.net> wrote in message news:<bp*********@drn.newsguy.com>...
dan said:

I have a script that selects a value in an option in a selection list
according to how many letters were entered in an input box. I have it
working but I am limited to what I can name the form fields because
they are dynamically created by a PHP script.

I can get it to work with simple name but not with names outputted by
the script. Is there a change I can make to the JavaScript so I can
use the dynamic names?

Simple name = 'letter_number'
Dynamic name = 'id[txt_3]'


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


so for
<input type="text" name ="id[txt_3]" size="6" maxlength="6" value="">
or
<input type="text" name ="id[5]" size="6" maxlength="6" value="">
I can access it with:
document.form_name.elements["id[txt_3]"].value.length
or
document.form_name.elements["id[5]"].value.length

???
thanks
???
Jul 20 '05 #3
Lee
dan said:

Lee <RE**************@cox.net> wrote in message
http://www.jibbering.com/faq/#FAQ4_25


so for
<input type="text" name ="id[txt_3]" size="6" maxlength="6" value="">
or
<input type="text" name ="id[5]" size="6" maxlength="6" value="">
I can access it with:
document.form_name.elements["id[txt_3]"].value.length
or
document.form_name.elements["id[5]"].value.length

???


Yes, and in less time than it took you to post this question,
you could have developed and tested a simple test case to
prove that to yourself:

<html>
<body onload="alert(document.form_name.elements['id[5]'].value)">
<form name="form_name">
<input name="id[5]" value="it works">
</form>
</body>
</html>

Jul 20 '05 #4
ry*****@yahoo.com (dan) writes:
I can access it with:
document.form_name.elements["id[txt_3]"].value.length
I prefer to use the forms collection. It is official W3C DOM, while
having the form directly as a property of the document element isn't.

document.forms["form_name"].elements["id[txt_3]".value.length
or
document.form_name.elements["id[5]"].value.length

???


Try it! (but yes!)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
dan wrote on 20 Nov 2003:
so for
<input type="text" name ="id[txt_3]" size="6" maxlength="6"
value="">
or
<input type="text" name ="id[5]" size="6" maxlength="6"
value="">

I can access it with:
document.form_name.elements["id[txt_3]"].value.length
or
document.form_name.elements["id[5]"].value.length


If "id[txt_3]" and "id[5]" are the names of the controls after being
parsed by the PHP interpreter, yes. However, you should change them.
The only valid characters in a control name are alphanumeric
characters, hyphens (-), periods (.), underscores (_), and colons
(:). Also, controls names must start with a letter.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #6
Michael Winter <M.******@blueyonder.co.uk.invalid> writes:
The only valid characters in a control name are alphanumeric
characters, hyphens (-), periods (.), underscores (_), and colons
(:). Also, controls names must start with a letter.


We had that discussion a while ago, and the conclusion was that
there are not restrictions on the names of controls.

In HTML 4, the value of the name attribute on input, textarea, select,
object and button elements are CDATA (and not NAME). While the
specification says:
---
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.
---
there are no such restrictions on the name attributes of form controls
(i.e., control names).

Control names and values are both escaped before sending as content
type "application/x-www-form-urlencoded".

Another quote from the specification (under "multipart/form-data"):
---
Control names originally encoded in non-ASCII character sets may be
encoded using the method outlined in [RFC2045].
---

That means that FAQ entry 4.25 is incorrect.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Lasse Reichstein Nielsen wrote on 21 Nov 2003:
Michael Winter <M.******@blueyonder.co.uk.invalid> writes:
The only valid characters in a control name are alphanumeric
characters, hyphens (-), periods (.), underscores (_), and
colons (:). Also, controls names must start with a letter.

Withdrawn. It just seemed a sensible association: name attributes of
NAME type.
We had that discussion a while ago, and the conclusion was that
there are not restrictions on the names of controls.
No leading and trailing spaces is probably one.
In HTML 4, the value of the name attribute on input, textarea,
select, object and button elements are CDATA (and not NAME).
While the specification says:
---
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.
---
there are no such restrictions on the name attributes of form
controls (i.e., control names).

Control names and values are both escaped before sending as
content type "application/x-www-form-urlencoded".

Another quote from the specification (under
"multipart/form-data"): ---
Control names originally encoded in non-ASCII character sets
may be encoded using the method outlined in [RFC2045].
---


It would appear that the NAME type is only used for language codes,
and the name and http-equiv attributes in META elements.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #8
Michael Winter <M.******@blueyonder.co.uk.invalid> writes:
Lasse Reichstein Nielsen wrote on 21 Nov 2003: Withdrawn. It just seemed a sensible association: name attributes of
NAME type.
Most of the people in this grouped had thought the same thing. We were
quite surpriced :)
We had that discussion a while ago, and the conclusion was that
there are not restrictions on the names of controls.


No leading and trailing spaces is probably one.


True. It is only a recommendation, but since browsers are free to
choose whether to strip the whitespace, writing it is asking for
trouble.
It would appear that the NAME type is only used for language codes,
and the name and http-equiv attributes in META elements.


Yes, that was my reading too.

For all other tags with name attributes, i.e., a, applet, form, frame,
iframe, img, and not control names, the specifiaction has this note:
---
Note. This attribute has been included for backwards
compatibility. Applications should use the id attribute to identify
elements.
---
Also, if you have both "id" and "name" attributes in the same
non-form-control tag, they must have identical values.
<URL:http://www.w3.org/TR/html4/struct/links.html#anchors-with-id>

Still, if you omit the "id" attribute, you can still give your images
"name" attributes that are not valid NAMEs.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9
Lasse Reichstein Nielsen wrote on 21 Nov 2003:
Also, if you have both "id" and "name" attributes in the same
non-form-control tag, they must have identical values.
<URL:http://www.w3.org/TR/html4/struct/links.html#anchors-with-id>


I hadn't noticed that. It seems odd to place such an important note
in such an inconspicuous place.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #10
JRS: In article <bp********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Thu,
20 Nov 2003 14:15:44 :-

Yes, and in less time than it took you to post this question,
you could have developed and tested a simple test case to
prove that to yourself:


A test case, executed in one or a few browsers, can prove that something
does not work in all systems; thus, one should test before asking. But
that cannot prove that it does work in all systems.

Asking here has a good chance of getting a reply valid at least for
almost all systems; it has greater coverage.

Referring to the FAQ 4.25 reference elsewhere in the thread :

ISTM that the FAQ should recommend that, where practicable, authors
should choose names following the usual conventions for identifiers in
computer languages - characters chosen from alphanumeric and underscore,
first character not a digit, and they should choose as for case-
independence.

Such names are computer-safe, human-safe, and look like names.

But it may be necessary to use names not following the above; and the
FAQ should give methods for using those (as well as commenting on
legality).

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #11

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

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
6
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: ...
1
by: ksrajalakshmi | last post by:
In a Solution, there may be many Windows Forms. To commit permission to all forms, i've to get the form names in the solution. Is there any proceedure for that?
8
by: ryan | last post by:
that will make sure all fields are entered. make sure age is between 3- 99 and make sure the email is valid I had a decent search on google, nothing really comes up that is complete. I am...
2
by: Agent Michael Scarn | last post by:
Hello, I need to be able to dynamically display all of the form names from a form I just submitted. I have a javascript which will display all the names of the form on the first page, but i...
2
by: mylo1968 | last post by:
Hello Experts, in the following link there is fine tool for javascript client-side form validation, as some of you I guess/hope know: ...
1
by: tomg | last post by:
How can I get all of my MS Access form names into an Excel file? thanks,
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
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: 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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.