Passing form field ID to JavaScript function

I Have an HTML form that looks like this

<form action='<?php echo($_SERVER["PHP_SELF"]) ?>' method='post' name='demoform'>

file:<input type=file name=link1 id=lnk1>
Date:<input type=text name=me id=ee onFocus="opnexl(,lnk1);">
file2::<input type=file name=link2 id=lnk2>
Date:<input type=text name=me id=aa onFocus="opnexl(,lnk2);">

I have a JavaScript function that needs to do something like this

function opnexl(nam,lnks)
var str=document.demoform.lnks.value;
if (str == "")
document.getElementById(nam).value= "0000-00-00 00:00:00";
var oExcel = new ActiveXObject("Excel.Application");
var oWB =;

The above code gives this error “document.demoform.lnks.value is null or not an object”. I guess the problem is the Id of the link fields are not being passed to the opnexl function. Does anyone know how I can get this program to work?

Thanks for any help you can give.

Because lnks is a variable, you’ll have to use an alternate notation

var str=document.demoform[lnks].value;

I tried it but it didn’t work. I still get the same error only now it is

“document.demoform[…] is null or not an object” .

Any ideas?

your passing lnk1 and lnk2 as an object and not as a string. The object is null since it doesn’t exist in scope.

it’d probably be 10x easier to do:



Works great!! Thanks very much.