...

View Full Version : strings?



nikko50
01-25-2009, 07:27 PM
If "key" holds the field name how do I insert key into "document.theForm.key.value"? Is what I did below correct?


document.theForm.+key+.value = value;

Philip M
01-25-2009, 07:38 PM
Use document.getElementById(key).value instead.

Example:-


<input type = "text" name = "txt1" id = "txt1" onblur = "chk()">

<script type = "text/javascript">
function chk() {
var key = "txt1"
var x = document.getElementById(key).value;
}
</script>


“Expert: a man who makes three correct guesses consecutively.”
Dr. Laurence J. Peter (American "hierarchiologist", Educator and Writer, 1919-1990)

nikko50
01-25-2009, 07:41 PM
So I can't reference by name?
Tracy

nikko50
01-25-2009, 07:56 PM
Thanks works great Philip!
Tracy

rnd me
01-26-2009, 12:59 AM
So I can't reference by name?
Tracy

there is a document.getElementsByName()

note that it returns a collection, not just a single tag like getById,
so document.getElementsByName("txt1")[0] is probably how you would want to use it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum