Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form field name as parameter to js function 1

Status
Not open for further replies.

oledawg

Programmer
Mar 7, 2001
2
JM
Hi all,

I have a js function where I pass in a form field name as a parameter, like

function myFunction(inFieldName) {

}

Within the function I would like to set the value of the field name I passed in, like

inFieldName.value = someValue ;

except that doesn't work. I tried

[inFieldName]value = someValue ; //and
[inFieldName].value = someValue ;

but none of those work either. Can this be done, and if so how?

 
how are you passing it in the event

it should be
function(this)
in case you are doing
this.value ---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
i find it easier to pass the form field object rather than its name. this way you can directly access it:

function foo(oField) {
oField.value = "foo";
}

<input type=&quot;text&quot; onblur=&quot;foo(this);&quot; /> =========================================================
if (!succeed) try();
-jeff
 
Thanks jemminger,

That's exactly what I wanted. (dunno why I didn't think of it!!) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top