[Javascript] problem accessing form field values

Bill javascript at unlockedideas.com
Fri Jan 25 11:15:00 CST 2002


Hi Folks:

I have a little problem that I hope someone can sort out with a quick glance. I am trying to create a function that will do the following:

* take as input two parameters
* use one of those parameters to identify which form field it should read the value of
* output a url with three parameters, those being the first two plus the value from the form field

I get an error when trying to dynamically access the value of the form field. Do I need to use eval() or something? What does that do anyway?

Here's some code that illustrates what I've got. Give it a try:

<script language=javascript>
<!--

function selector(myCat,myField) {
var st = document.forms[0].myField.value;
document.write ('sel.asp?c=' + myCat+ '&f=' + myField + '&st=' + st)
}

//-->
</script>

<form>
<input type="text" name="emp">
<input type=button value="..." onClick="selector('intl','emp')">
</form>

But instead of giving me a window with the following (and which does come when hard coding 'var st' with 'document.forms[0].emp.value'):

sel.asp?c=intl&f=emp&st=user_input

I am stuck with this:

Error: 'document.forms.0.myField.value' is null or not an object.

Any help would be great. Thanks.

Bill



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20020125/8db15123/attachment.htm>


More information about the Javascript mailing list