Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Eval?


  • From: javascript@xxxxxxxxxx (Peter-Paul Koch)
  • Subject: [Javascript] Eval?
  • Date: Fri, 19 Jul 2002 06:30:22 +0000

>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