...

View Full Version : WHY isn't this working? EASY..object has no properties...passing form name/elementnam



BrightNail
07-24-2002, 11:57 PM
hey all,

why am I having a brain fart on this...its easy..what obvious thing am I missing?

I am passing the "form name & element name" via function call..

inputValues('carform.textdata','17.00')

to a function...but when I try to "use" the passed variable, I get errors "blah blah..has no properties.

function inputValues(boxName, boxValue){
document[boxName].value=boxValue;
}

I've tried everything..
document(boxName).value=boxValue
document.boxName.value
document.[boxName].value
with periods, without..with brackets, without...
etc..
etc..

when I throw an alert..the CORRECT value is in the variable name..when I hard code it..
document.carform.textdata.value
it works just fine...

what is the deal?..is it interpreting the value as a non-string... dont' know..help..
thanks,
james

adios
07-25-2002, 12:04 AM
Not quite everything...

inputValues(carform.textdata,'17.00')

inputValues(carform['textdata'],'17.00')

inputValues(document['carform']['textdata'],'17.00')

inputValues(document.carform.textdata,'17.00')

You're trying to fix the wrong end of things (the function - where only eval() - maybe - would help). The document. reference is probably necessary, too. All an alert() will show is a string version of what you pass it; using the typeof operator often helps. In this case: string.

The dot is part of 'dot syntax'; using string indices (indexes) is a different notation altogether. Mix them carefully.

BrightNail
07-25-2002, 01:03 AM
thanks for your reply,

but none of those worked...

try it out....

here is the link:

<form name=carform>
<input type=text name="datebox" size=15><a href="javascript:inputValues('carform.datebox','17.00');" onmouseover="window.status='some info';return true;" onmouseout="window.status='';return true;">CHANGE</a></form>


Here is the function:

function inputValues(boxName, boxValue){
document.boxName.value=boxValue;
}



as you can see, all very very easy...but doen't work..I tried all your solutions and mine...but its not "recognizing the "object"...has no properties...darn...

adios
07-25-2002, 01:07 AM
<form name=carform>
<input type=text name="datebox" size=15><a href="javascript&#58;void inputValues('datebox','17.00');" onmouseover="window.status='some info';return true;" onmouseout="window.status='';return true;">CHANGE</a></form>


Here is the function:

function inputValues(boxName, boxValue){
document.carform[boxName].value=boxValue;
}

BrightNail
07-25-2002, 09:35 AM
I DELETED THIS POST cause I found a solution

BrightNail
07-25-2002, 10:02 AM
YEAH>>>

I FOUND A SOLUTION..get it out...

I found that if I put them seperate ....
inputValues('carform','datebox','17.00');
IT WORKS!>..but...I can't have "3" values passed...only 2. so, I see that it creates a possibility....

so,,,,I decided to "split" the first variable into '2' into the function and then USE them...so, this is what i have...

function inputValues(boxName,boxValue){
var result=boxName.split(".");
document[result[0]][result[1]].value=boxValue;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum