Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Participant ,
Feb 11, 2009 Feb 11, 2009
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
TOPICS
Advanced techniques
625
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2009 Feb 11, 2009
Where you say, "This is parts of the form, passing the info", there is nothing that calls your js function.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 11, 2009 Feb 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2009 Feb 11, 2009
Still nothing in the code you post that calls your js function.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 11, 2009 Feb 11, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2009 Feb 11, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 11, 2009 Feb 11, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2009 Feb 11, 2009
yes, when you submit the form via js, the submit button is not 'clicked'
and thus it is not submitted with the form.

what you need to do is create a hidden field and populate it with some
value in your js function, then check for that field and its value on
the action page.

something like this:

--the form:

<form name="myform" id="myform" ...>
<input type="hidden" name="form_action" id="form_action" value="">
...
</form>

--js:

function confirmDelete(ID_Field,ViewField1) {
if (confirm ("Are you sure you want to delete " + ViewField1 + " event?"))
{
document.myform.action="ProjectCat-Action.cfm?id="+id;
document.myform.form_action.value="EventView_Edit";
document.myform.submit();
}
return false;
}

--action page:

<cfif isDefined("Form.EventView_Edit") OR (isdefined("form.form_action")
AND form.form_action eq "EventView_Edit")>
...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 11, 2009 Feb 11, 2009
That works perfectly! Thank you!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 12, 2009 Feb 12, 2009
LATEST
That works nice, but now I have a question, how do I catch the id that is being passed by it? I need to use this:

<cfif isDefined("URL.ID")>
This code throws an error when I add a new record.
I also tried
<cfif isDefined("URL.RecordID")>
and this doesn't work either way.

Now if there is a different variable I am grabbing from your code, this is good, because I can make a statement that shows if a record was added or if one was updated.

Is the ID different with your code? How do I grab it on another page?

Also, if it is, I want to make 2 statements, 1 for my code that works and one for the code I need to grab the id from what you wrote.

CFmonger
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources