Jump to content

Java Script Help


Recommended Posts

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 !!!

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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;

*********************************************************************************************************************************************************

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...