Skip to main content
Inspiring
February 11, 2009
Question

Passing a variable, and losing it in java scripting. Please help

  • February 11, 2009
  • 3 replies
  • 852 views
Hello;
I am upgrading a lot of my code to cf 8, some of it was running on old code. I made a lot of serious changes and I ran into a problem in doing things this way.

Here is what I am trying to do.

I have an app that has a number of different pages doing a number of different things, adding records, inserting new ones an so on. I made 1 page called action.cfm this page has all my controls on it for all these sections of the app. To set off the appropriate code, I am using an if statement like this:

<cfif isDefined("Form.EventView_Edit")>
and it sets off the code for that form. the submit button on the form is called: EventView_Edit

Now, I am trying to pass this information through a java script I use to ask you if you really want to delete a record.

This is that script:
<script language="JavaScript">
function confirmDelete(ID_Field,ViewField1) {
if (confirm ("Are you sure you want to delete " + ViewField1 + " event?"))
{
document.HREF.action="ProjectCat-Action.cfm?id="+id;
document.HREF.submit();
}
return false;
}
</script>

This is parts of the form, passing the info.

<form action="Action.cfm" method="post">
<input type="submit" class="formButtons" name="EventView_Edit" value="Delete">
</form>

It was working fine when I had this secrions operators on it's own page, but now that I am narrowing it down with a lot of code for a number of items, it is missing the delete function because the name of the form button is not passing through the java.

How do I fix this?
Also, is there a better way of doing what I am doing? Or is this pretty much it?

Thank you.
CFmonger
This topic has been closed for replies.

3 replies

Inspiring
February 12, 2009
Changing a form to an href complicates things and does not seem to add any value. Something like this, http://www.shiningstar.net/articles/articles/javascript/confirmsubmit.asp, is much more straightforward.
CFmongerAuthor
Inspiring
February 12, 2009
I might just pass the delete functions off on their own page and let it work that way. I was trying to do away with a lot of pages of code, but I don't think I can with what I am trying to do.

I am reading over your link, thank you. I'll give it a try.

CFmonger
Inspiring
February 12, 2009
Still nothing in the code you post that calls your js function.
CFmongerAuthor
Inspiring
February 12, 2009
Sorry, forgot that part:

This is in the delete button:

onClick="return confirmDelete('ID_Field','#ViewField1#')"

<form action="Action.cfm" method="post">
<input type="hidden" name="RecordID" value="#ID_Field#">
<input type="submit" class="formButtons" name="EventView_Edit" onClick="return confirmDelete('ID_Field','#ViewField1#')" value="Delete">
</form>

Sorry. my bad
Inspiring
February 11, 2009
Where you say, "This is parts of the form, passing the info", there is nothing that calls your js function.
CFmongerAuthor
Inspiring
February 11, 2009
Sorry, I forgot the hiddnen field:

<form action="Action.cfm" method="post">
<input type="hidden" name="RecordID" value="#ID_Field#">
<input type="submit" class="formButtons" name="EventView_Edit" value="Delete">
</form>

and then my java script:

<script language="JavaScript">
function confirmDelete(ID_Field,ViewField1) {
if (confirm ("Are you sure you want to delete " + ViewField1 + " event?"))
{
document.HREF.action="ProjectCat-Action.cfm?id="+id;
document.HREF.submit();
}
return false;
}
</script>

When you hit delete, it gets the java script, has all the right info, but it is not passing the name, name="EventView_Edit" of the submit button so it will activate the delete code on teh action.cfm file.