/    Sign up×
Community /Pin to ProfileBookmark

Referencing numeric field name problem

Hello all,

I do hope you guys can help me…

This is my problem:

I have a dynamic page where each row is populated from the DataBase, one of the fields is a dynamically populated dropdown select. It has a numeric field name (userid) also coming from a DB.

I need to manipulate these dropdowns, and I am having a major problem referencing a numeric field name in JavaScript.
(Basically, I let the user change all of the dropdowns values to one single chosen value in the static select).

I cannot change the fieldname, it must remain numeric…

emptyList( box.form.FieldNameHere );
fillList( box.form.FieldNameHere, list );

Any ideas how to reference a numeric field name?

Thank you so much for your replies…
? ? ?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Aug 20.2004 — Instead of referring to it as:document.form_name.element_nameyou can use:document.form_name['numeric_name_goes_here'](Note that is doesn't have to be numeric, although the first method must be a string. Surround the numbers in quote, since the name property is always a string.

Dr. Script
Copy linkTweet thisAlerts:
@croftauthorAug 20.2004 — Hi, thanks for replying...

Unfortunately this works great for everything but the numeric:

emptyList( box.form['testslave1'] );
fillList( box.form['testslave1'], list );


// Doesn't work below...

emptyList( box.form['20084'] );

fillList( box.form['20084'], list );

..........

<select name="testslave1" size=1>

<option value="A" SELECTED>Active

<option value="I">Inactive

</select>

<select name="20084" size=1>

<option value="A" SELECTED>Active

<option value="I">Inactive

</select>


Any idea?..

THANKS!!!!!
Copy linkTweet thisAlerts:
@steelersfan88Aug 20.2004 — Sorry 'bout that. Since the rules for names are:

1) Start with a letter ([A-Za-z])

2) Any word/number character ([A-Za-z0-9_])

You will not be able to reference it this way. You can reference it by the element number in the form:document.form_name.elements[#]#0 refers to element #1

#1 => #2

#2 => #3

Dr. Script
Copy linkTweet thisAlerts:
@CharlesAug 20.2004 — Better yet, modify your DataBase a wee bit and preface all of those numbers with a letter. There's no excuse for invalid HTML.
Copy linkTweet thisAlerts:
@croftauthorAug 21.2004 — Thx, Dr.Script...

I will try that on Monday...

It will however present me with another problem...

The number of rows (elements) is determined dynamically, so I guess I will have to figure out how to iterate through...

(Not easy, it's Struts/JSP/Java framework, data comes from a resultsbean - very modular...)
--



Charles - I wish I could change the DB a "wee bit"... lol... but it is a complete impossibility in this case. It is a huge database and the application is not any smaller and very dependent on this numeric id. All procs and SQL are using it...
--



Thank you again for looking into my problem and replying.

I appreciate all the help I can get!

Have a great weekend!

Croft. ?
Copy linkTweet thisAlerts:
@CharlesAug 21.2004 — You don't need to change the data base itself, just that one line of the script that writes the ID. If you were working in Perl it would simply be:

[font=monospace]print <<EOQ

<select name="n20084" size=1>

<option value="A" SELECTED>Active

<option value="I">Inactive

</select>

EOQ[/font]

And then when you process the form you might need to remove the "n".
×

Success!

Help @croft spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...