Accountability Posted February 13, 2013 Report Share Posted February 13, 2013 Please need help with the following: Psudo Code> If> Field: Breakfast (Check Box) = "Yes" And> Field: Present (Check Box) = "Yes" Replace> Field: Breakfast_Charge (Numeric) with the value of> Field: Breakfast_Amount (Numeric) If> Field: Lunch (Check Box) = "Yes" And> Field: Present (Check Box) = "Yes" Replace> Field: Lunch_Charge (Numeric) with the value of> Field: Lunch_Amount (Numeric) Else> Do Nothing ****************************************************************************************************************************************************** Here is the code I attempted but does not work: if("[@Lunch]" == "Yes") && if("[@Present] == "Yes"){ function Lunchcharge() { var LCharge= document.getElementById("InsertRecordLunch_Amount").value"; document.getElementById("InsertRecordLunch_Charge").value = LCharge; } document.getElementById("caspioform").onsubmit=Lunchcharge; } if("[@Breakfast]" == "Yes") && if("[@Present] == "Yes"){ function Breakfastcharge() { var LCharge= document.getElementById("InsertRecordBreakfast_Amount").value"; document.getElementById("InsertRecordBreakfast_Charge").value = LCharge; } document.getElementById("caspioform").onsubmit=Breakfastcharge; } ********************************************************************************************************************************************* Thanks You in Advance for Your Help !!! Quote Link to comment Share on other sites More sharing options...
MayMusic Posted February 13, 2013 Report Share Posted February 13, 2013 Try this JS and let me know if it helps?! <SCRIPT LANGUAGE="JavaScript"> Stamp = new Date(); var v_TimeStamp; Hours = Stamp.getHours() Mins = Stamp.getMinutes(); if (Mins < 10) { Mins = "0" + Mins; } v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins); document.getElementById("InsertRecordAttendance_Meal_Date").value=v_TimeStamp; function charge(){ if ((document.getElementById("InsertRecordLunch").checked) && (document.getElementById("InsertRecordPresent").checked)) { document.getElementById("InsertRecordLunch_Charge").value= document.getElementById("InsertRecordLunch_Amount").value; } else { document.getElementById("InsertRecordLunch_Charge").value = 0 ; } if((document.getElementById("InsertRecordBreakfast").checked) && (document.getElementById("InsertRecordPresent").checked)){ document.getElementById("InsertRecordBreakfast_Charge").value = document.getElementById("InsertRecordBreakfast_Amount").value; } else { document.getElementById("InsertRecordBreakfast_Charge").value = 0 ;} } document.getElementById("caspioform").onsubmit=charge; </script> Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 13, 2013 Author Report Share Posted February 13, 2013 It did insert the Attendance_Meal_Date properly but the Breakfast_Charge and Lunch_Charge were not inserted. Any ideas ? Once again I am very grateful for your help. THANK YOU !!! Quote Link to comment Share on other sites More sharing options...
MayMusic Posted February 13, 2013 Report Share Posted February 13, 2013 Open the page in Caspio and try it from there and see if it works in Caspio. If it does then that means you have more than one caspio page and JS cannot guess which page you are referring to by saying caspioform.onsubmit. Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 14, 2013 Author Report Share Posted February 14, 2013 I did try from Caspio. It did not post the Lunch_Charge or the Breakfast_Charge ( as expected0 but it did post a 0 value when check make was not selected (as expected). Quote Link to comment Share on other sites More sharing options...
MayMusic Posted February 14, 2013 Report Share Posted February 14, 2013 Maybe field IDs are not matching you need to make sure are the IDs are correct! Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 14, 2013 Author Report Share Posted February 14, 2013 I checked and all field names appear to be correct. Also I did notice that When a "0" value (via the else) is expected it is properly inserted into the Lunch_Charge or Breakfast_Charge fields. If I select "Lunch" or "Breakfast" check boxes I get a blank Lunch_Charge or blank Breakfast_Charge. If I leave both check marks blank I get a "0" value in Lunch_Charge and Breakfast_Charge fields as expected. It appears to be partially working because both fields are populated with "0" when expected. This was tested in Caspio and not from the .html. Anything else I should consider ? Thanks Again ! Quote Link to comment Share on other sites More sharing options...
MayMusic Posted February 14, 2013 Report Share Posted February 14, 2013 you need to replace "InsertRecordPresent" with "InsertRecordAttendance_Present" in the code. Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 14, 2013 Author Report Share Posted February 14, 2013 Thank you for catching that. It works perfectly in Caspio but does not on the actual web page. I do have another datapage on the same page. And I will probably have two or three more datapages on this page. Do you think that is the issue ? If I had to, I could probably create a view and incorporate all in one datapage, if I have to. Thank you again for taking the time to help me. Please know that it is deeply appreciated. Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 15, 2013 Author Report Share Posted February 15, 2013 I have since removed the other datapage and it works perfectly on the page. Is there any way for me to have more datapages on the same html page ? Is there a way to specify in the JS that specific form ? Also, just as a learning moment for me, if it is possible to isolate or properly reference specific forms, is it possible for the other datapages to contain JS within HTML blocks or will that cause problems for the JS currently in question. As always THANK YOU!!! Quote Link to comment Share on other sites More sharing options...
MayMusic Posted February 15, 2013 Report Share Posted February 15, 2013 Add this to the header of the page: and to the footer before all JS codes: and then replace document.getElementById("caspioform").onsubmit=charge; with document.getElementById('cb_wrapper').getElementsByTagName('form')[0].onsubmit=charge; Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 15, 2013 Author Report Share Posted February 15, 2013 Thank for responding. I did exactly as instructed. It did insert as expected but when it refreshed and returned to the page the form with the JS was not there (Just a few letters) where the form was. Any thoughts ? Thank You ! Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 15, 2013 Author Report Share Posted February 15, 2013 OOPS... I spoke too soon. The destination had to be changed. It Works GREAT !!!!! I can't THANK YOU ENOUGH !!!! You are fantastic !!! Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 15, 2013 Author Report Share Posted February 15, 2013 If I have another form with JS on the same HTML page, do I just change the id="cb_wrapper" to cd1_wrapper, cd2_wrapper, etc. ? (and also the corresponding document.getElementById('cb_wrapper') to document.getElementById('cb1_wrapper'), document.getElementById('cb2_wrapper') etc. Is this correct ? Thank again... ********************************************************************************************************************************************************* Add this to the header of the page: and to the footer before all JS codes: and then replace document.getElementById("caspioform").onsubmit=charge; with document.getElementById('cb_wrapper').getElementsByTagName('form')[0].onsubmit=charge; ********************************************************************************************************************************************************* Quote Link to comment Share on other sites More sharing options...
bahar_vm Posted February 16, 2013 Report Share Posted February 16, 2013 That's correct! Best, Bahar M. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted February 19, 2013 Report Share Posted February 19, 2013 Yes, try the earlier post at Fri Feb 15, 2013 12:50 pm. That works for sure :wink: :wink: Quote Link to comment Share on other sites More sharing options...
Accountability Posted February 20, 2013 Author Report Share Posted February 20, 2013 THANK YOU AGAIN !!! You guys are the Best... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.