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

Varable name & form 1

Status
Not open for further replies.

Palmke

Programmer
May 12, 2004
16
IT
Hi all,

I made a function like this :

function save_state(id,field)
{...
//I do some stuff and then this line
myform.field.value=1;
...}

if I make it run, the system doesn't save anything in value of field, I looked everywhere how to write field since is a variable, when you usually use +field+ if like you have to print it but nothing worked.

May anybody help me please?
 
Where is "myform" defined? If "myform" is the form name, and "field" is a string containing the field name, then use this instead:

Code:
document.forms['myform'][field].value = 1;

Shortcutting around DOM methods only short-changes yourself in the long run!

Hope this helps,
Dan
 
Real thanks! it worked :)

Now I have two more problems :

1) I have to use the function that I wrote to save something under the column called "field" in that form,
in the same form there's another column which I may call it "user number" that it is not autoincrement but it's the key field and every row has a different number in it.
Now, by calling the function again and again it always writes on the same row, but I need to make it write on the line of the "user" that is actually being referred by that form! I really don't have a clue how to do that.
Today it's my 'first day' of Javascript ...

2) I have to use event handlers for some kind of buttons,
I also have to make it react when you click on + or - buttons of a counter.. i tried onclick and onchange but both of them reacts when the text in it is clicked...
Any help?

Best regards,
Palmke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top