Avatar of jriver12
jriver12
 asked on

Setting update value after form submission via ajax proxy (javascript/coldfusion)

Hey all got yet another issue that is raking my brain.  here is my situation:
I have a cfm page that is using the layout for processing of inline forms, upon save the page calls (via ajax proxy) a cfc page that funs a function (insert).  after the successfull insert of the record I am not clearing the form fields since other maintenance on the record will and can be done, however when I hit submit again the record is being inserted again vs being updated.  My question is how do I set a variable that either through the cfc or through ajax once the record is submitted the form would know that the next click of the button would be an update.
I can post the functions and form if need be.
thanks.
Web Development SoftwareJavaScriptColdFusion LanguageProgramming

Avatar of undefined
Last Comment
jriver12

8/22/2022 - Mon
Michel Plungjan

<form onSubmit="this.submitted.value='true'">
<input type="hidden" name="submitted" />
jriver12

ASKER
understanding that this will set the hidden field to true when submitted.  so would I do a check
if form.submitted == submited {
function updateAttd()
{
ColdFusion.Ajax.submitForm ('AttendeeUpdate', 'AttendeeCom.cfc?method=UpdateAttendee') ;

}
?
ASKER CERTIFIED SOLUTION
Michel Plungjan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

Or just read the submitted value on the server
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
jriver12

ASKER
ok getting a form undefined when hitting that function:
------window:global: 'form' is undefined (http://localhost/ipereg/CreateNew.cfm?cfdebug, line 212)----
I am assuming it is here:
if (form.submitted.value == 'true')
By nature I beleive that the ajax is passing the form name as  "AttendeeUpdate"

should I modify the "form." to be AttendeeUpdate..
jriver12

ASKER
Did this and it seem to work,
function AttendeeActions() {
 if (document.getElementById("SUBMITTED").value = 'true') {
   ColdFusion.Ajax.submitForm ('AttendeeInsert', 'AttendeeCom.cfc?method=UpdateAttendee') ;
 }
 else {
   ColdFusion.Ajax.submitForm ('AttendeeInsert', 'AttendeeCom.cfc?method=CreateAttendee') ;
 }
}

getting an error on a field but I think it is not relevant to this post.  Give me a bit to double check.
jriver12

ASKER
seems to be working however I am having an issue passing arguments between two. cffunctions.
are you familiar with that process.  I will post another Q in its respective area.  
thanks again.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jriver12

ASKER
I beleive I spoke too soon on this one. (my apologies) Over the past few days I have been trying to validate the insert which is working however getting the SUBMITTED to carry over and have the script see the update is failing.  I have tried everything I could think of.
any further help would be great.

I will attach my files.
component.txt
form.txt
milagro.txt
jriver12

ASKER
Thanks Cooleomod.  It is appreciated.  I do feel that those who commented did provide valid solutions however as I stated I just think my issue is a bit more complex.?

Thanks again.
Michel Plungjan

Perhaps delete and re-ask since I do not have much CF knowledge
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
jriver12

ASKER
Mplungian,  the issue is not with the cf.  What I have noticed is that on the js.
<form onSubmit="this.submitted.value='true'"> - - -here
it is setting the field to true prior to the action completing whereby as soon as I click it tries to do a update vs an insert.  once inserted I need to set to true.  I could have sworn this code worked at first glance but then when I looked a bit deeper it was not.

is there a way to delay the write to true?  here?
function AttendeeActions() {
 if (document.getElementById("SUBMITTED").value = 'true') {
   ColdFusion.Ajax.submitForm ('AttendeeInsert', 'AttendeeCom.cfc?method=UpdateAttendee') ;
 }
 else {
   ColdFusion.Ajax.submitForm ('AttendeeInsert', 'AttendeeCom.cfc?method=CreateAttendee') ;
 }
}

I don't think a repost and or deletion is necessary since the code provided can still be used and repurposed in other directions.

jriver12

ASKER
ok, I took the onsubmit="function" off the form and altered the hidden formfield "submitted" to false as default, and altered the js as such:

if (document.getElementById("SUBMITTED").value = 'false')
{
   ColdFusion.Ajax.submitForm ('AttendeeUpdate', 'AttendeeCom.cfc?method=CreateAttendee') ;
   document.getElementById("SUBMITTED").value = 'true'
 }
 else {
   ColdFusion.Ajax.submitForm ('AttendeeUpdate', 'AttendeeCom.cfc?method=UpdateAttendee') ;
 }

now theoretically that should work. but for some reason it still creates an new record, the debugger shows the value of submitted is till coming in as false although the form field shows true.  HMM.  any thing else you can think of that I have missed.
}
jriver12

ASKER
thanks for the help
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

I am sorry. I do not see how I missed this.

Your last issue is with == (equals) and = (assign value)

You want



if (document.getElementById("SUBMITTED").value == 'false') {
   ColdFusion.Ajax.submitForm ('AttendeeUpdate', 'AttendeeCom.cfc?method=CreateAttendee') ;
   document.getElementById("SUBMITTED").value = 'true'
 }
 else {
   ColdFusion.Ajax.submitForm ('AttendeeUpdate', 'AttendeeCom.cfc?method=UpdateAttendee') ;
 }

Open in new window

jriver12

ASKER
mplungian, I worked on it last night and found that too. the script is now functioning correctly thanks.