ColdFusion Programming/how to submit a coldfusion form using a button and perform some action on the same page
Expert: Donald Hammond - 7/23/2008
QuestionHi,
I have a query and i am really struggling with it. Below are the details
" In my cfm page I need to validate input fields before I submit my page, therefore i cannot keep the input type as submit for submit (as it will submit the page whatsoever). So i kept the type for submit as button and when it returns true I am redirecting to same page.
My problem is that when return is true I need to perform some action. i am just not getting how to do it:
My code is as below:
function funcSaveFinal()
{
alert(funcSave());
if(funcSave()==true)
{
var saveButton=document.getElementById('save');
var saveAction=document.getElementById('saveAction1');
saveAction.value=saveButton.value;
alert(saveAction.value);
<!---var SaveHolidayForm =document.getElementById("frmHolidayList");
SaveHolidayForm.action = "holidaylists.cfm";
//alert(SaveHolidayForm.action)
SaveHolidayForm.method = "post";
SaveHolidayForm.submit();--->
//saveAction.value=saveButton.value;
}
}
<CFINPUT name="Save" type="button" value="Save" id="save" onClick="funcSaveFinal();">
Please reply. I need help on this
AnswerAloha,
Actually you DO want your action to be SUBMIT. The key is in the form tag you use onSubmit=somefunction()
<form name="myForm" action="someURL" onSubmit="validateme()">
The javascript must then do its thing and at the end have a return value of true or false depending on if you want the form to continue on to someURL
Take a look at this page
http://www.w3schools.com/js/js_form_validation.asp
It gives a good example. There are plenty of other examples. Just search on javascript form validation
And your javascript seems flawed too. But that is another matter.