Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Trouble changing the value of an input
Old 07-25-2011, 04:15 PM Trouble changing the value of an input
Super Talker

Posts: 113
Trades: 0
This works fine to change an input:

Code:
document.theform.f10.value = 'test';
But the input that gets changed needs to be based on a variable in the function. So, it needs to work like this:

Code:
var input = "f10";
document.theform.input.value = 'test';
But I can't get it to work.

Any advice?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-25-2011, 04:25 PM Re: Trouble changing the value of an input
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You could always use the getElementByID() function. Add an ID value to your input field
(<input id="some_id" ... />), and access it by

Code:
getElementByID('some_id').value = 'test';

// or if you need to access it several times
var elem = getElementByID('some_id');
elem.value = 'test';
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 07-25-2011, 06:49 PM Re: Trouble changing the value of an input
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I think you mean something like this...

Code:
var input = "f10";
document.theform[input].value = 'test';
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Trouble changing the value of an input
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56802 seconds with 12 queries