[Javascript] Eval?

Peter-Paul Koch gassinaumasis at hotmail.com
Fri Jul 19 01:30:22 CDT 2002


>lack of knowledge in this area. The variable that I am having trouble with 
>is 'formName' The following code returns the error "ID is null or not an 
>object" or something similar:
>
>html:
><!-- here I am trying to pass in the variable -->
><a href="javascript: deleteBond(#ID#,'myForm');">Del</a>
>
>javascript:
>
>function deleteBond(id,formName){
>	if (confirm('Are you sure you want to delete this record?')){
>		/* The code blows up on the line below when trying to evaluate (ooooh 
>wait
>do I have to evaluate??? maybe I'm on to something...) the formName
>attribute */
>		window.document.+formName+.ID.value = id;
>		window.document.+formName+.action.value = 'delete';
>		window.document.+formName+.submit();
>	}
>}

You can use eval() but don't need to. Do

document.forms[formName].ID.value

The forms array accepts the name of a form as a key, so forms[formName] 
always works fine.

ppk

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




More information about the Javascript mailing list