By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

strings..

P: n/a
var myform= document.formPricing;
var one = "price";
alert(one);

var amount = myform.one.value;

the alert prints name of element fine, however, on line

var amount = myform.one.value;

I get error 'one.value is null or not an obj'... (and element is not
empty..) I don't get this.. thank you...
Sep 27 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

Be more precise and specific or paste your relevant code for us to see what
you have.

Danny
Sep 27 '05 #2

P: n/a
Frances Del Rio wrote:
var myform= document.formPricing;
var one = "price";
alert(one);

var amount = myform.one.value;

the alert prints name of element fine, however, on line

var amount = myform.one.value;

I get error 'one.value is null or not an obj'... (and element is not
empty..) I don't get this.. thank you...

disregard pls -- had to do:

eval('myform.' + one + '.value');

Sep 27 '05 #3

P: n/a
Without knowing exactly what you're up to, i can't be sure, but for
most every case i've seen, you can do

myform['one'].value

which doesn't rely so heavily on eval, which, while a powerful tool,
isn't always necessary and can often be replaced with something more
mundane if you look for some alternate syntax. :)

-Brendan

Sep 27 '05 #4

P: n/a

Frances Del Rio wrote:
var myform= document.formPricing;
var one = "price";
alert(one);

var amount = myform.one.value;

the alert prints name of element fine, however, on line

var amount = myform.one.value;

I get error 'one.value is null or not an obj'... (and element is not
empty..) I don't get this.. thank you...


It appears you don't understand how to access form elements.

To do what you wanted to as above then you should've done it like so:

myform.price.value

I prefer to do it this way:

document.forms["form name"].elements["form element name"]

Sep 27 '05 #5

P: n/a
On 27/09/2005 22:52, Donius wrote:

[snip]
myform['one'].value


If one is a variable, which it is supposed to be in the OP, then omit
the quotation marks:

myform[one].value

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Sep 28 '05 #6

P: n/a
Frances Del Rio said the following on 9/27/2005 5:36 PM:
Frances Del Rio wrote:
var myform= document.formPricing;
var one = "price";
alert(one);

var amount = myform.one.value;

the alert prints name of element fine, however, on line

var amount = myform.one.value;

I get error 'one.value is null or not an obj'... (and element is not
empty..) I don't get this.. thank you...


disregard pls -- had to do:

eval('myform.' + one + '.value');


No, you did not have to do that. eval is *not* needed there. 99% of the
uses of eval (if not higher) on the web is the lack of understanding on
the part of the person who wrote it.

myform[one].value;

Look Ma, No eval!

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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 28 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.