Jump to content

Simple Javascript if else


Recommended Posts

I'm trying to insert values in fields in an Submission Page based on the values of adjacent fields.

The script is in the Footer. It is not working. The Organizer_Fee, Yearbook_Fee and BookClub_Fee are being populated with the "Yes" value every time.

Here's my script:

function calculate()

{

var order_organizer = (document.getElementById("InsertRecordOrganizer"));

var order_yearbook = (document.getElementById("InsertRecordYearbook"));

var order_bookclub = (document.getElementById("InsertRecordBookClub"));

if (order_organizer = "Yes")

{

document.getElementById("InsertRecordOrganizer_Fee").value = (10);

}

else

{

document.getElementById("InsertRecordOrganizer_Fee").value = (0);

}

if (order_yearbook = "Yes")

{

document.getElementById("InsertRecordYearbook_Fee").value = (25);

}

else

{

document.getElementById("InsertRecordYearbook_Fee").value = (0);

}

if (order_bookclub = "Yes")

{

document.getElementById("InsertRecordBookClub_Fee").value = (50);

}

else

{

document.getElementById("InsertRecordBookClub_Fee").value = (0);

}

}

/* On submitting the webform, the function calculate is executed */

document.getElementById("caspioform").onsubmit=calculate;

Link to comment
Share on other sites

hello,

I see that you have only one '=' for 'if' statement. The comparison should always be '=='. Also, I don't know if

document.getElementById("InsertRecordBookClub_Fee").value = (0); is how we assign value to a field. I have always used like: document.getElementById("InsertRecordBookClub_Fee").value = 0;

i.e without brackets in the value.

:)

Link to comment
Share on other sites

When trying to access a form element, the type of the form element is important. For example if the form element is a radio, the way you reference it in the script is different. Example:

If Organizer is a radio button, note that a radio button element normally does not have an ID for itself however each option of the radio button has it’s own ID which can be referenced as: InsertRecordNameX

X can be 0 for the first option, 1 second option and so far…

So you may need to make some changes to your script.

Best,

Bahar M.

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...
×
×
  • Create New...