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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascrit function

Status
Not open for further replies.

mike10101

Vendor
May 6, 2005
13
GB
Hello,

when setting a field in a document to a specific value like below,

document.Form1.qnt_handmic.value = 0

Is it possible to use a variable instead of specifying the textfield 'qnt_handmic'

I have tried to illustrate what i'm trying to achieve here.

function quantity(current_texfield) {

var strname = document.Form1.current_texfield.value
if (strname > 0 ) {
document.Form1.current_texfield.value = 0
}

any help would be greatly apreciated
 
Code:
document.forms['Form1'].elements[current_textfield].value = 0;

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
brilliant.. I think I must have tried everything apart from that.

thank you very much.
 
That's one of the problems with usingthe easy (and non-standard) way of referencing form fields by bypassing the forms and elements collections. It only works under certain conditions, and hides the fact that there is a MUCH more flexible method that IS standard. Using the forms and elements collections you can even mix constant and variable values. For example:
Code:
var x = "A";
var y = 1;
document.forms['form'+x].elements['field'+y].value = 0;
'refers to element field1 in form formA


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top