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 (Andrew Peterson)
  • Subject: [Javascript] Eval?
  • Date: Thu, 18 Jul 2002 12:23:14 -0500

Hi,

I have multiple forms on one html page, and am trying to pass in a form name
into a javascript function so that I can tell the javascript function what
form to run against, but I cannot properly assign a variable to it due to my
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();
	}
}


This code works fine, however:


<a href="javascript: deleteBond1(#ID#);">Del</a>


function deleteBond1(id){
	if (confirm('Are you sure you want to delete this record?')){
		window.document.form1.ID.value = id;
		window.document.form1.action.value = 'delete';
		window.document.form1.submit();
	}
}

I just want to prevent having to write a javascript function for every form
I have in the html page simply because I cannot figure out how to pass in
the form name. Any help is greatly appreciated. Meanwhile, I'm going to work
with the eval() function to see what I come up with

Thanks in advance,
Andrew