...

View Full Version : Beginner --> Appending string to DOM document.form.input(appendhere).value



supergrover
09-02-2008, 11:33 AM
Hi all,

I'm new to Javascript, and having a little trouble figuring out how to append strings to DOM assignments.

To be specific:

var appendhere = 'firstfield';
document.form.input(want to put 'appendhere' in here).value = myvalue;

I want to be read as "document.form.inputfirstfield.value". I'm guessing there's a simple solution for this, but unfortunately google doesn't seem to be of any help. "input+appendhere" outputs literally as document.form.input+appendhere.value.

Any help appreciated - many thanks.

- SuperGrover

Philip M
09-02-2008, 12:42 PM
I am not too clear as to what you are trying to achieve, but this may help you:-




<input type = "text" name = "inputfirstfield" id = "inputfirstfield">

<script type = "text/javascript">
var myvalue = "abcdefgh";
var appendhere = 'firstfield';
var x = "input"+ appendhere;
document.getElementById(x).value = myvalue;
</script>


Q. If you were to spell out numbers, how far would you have to go until you would find the letter "A"?
A. One thousand



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum