/    Sign up×
Community /Pin to ProfileBookmark

Assign Value from Field

I am creating a form for a SugarCRM module. This file, EditView.html, is the only file I want to edit and this file contains the html code that goes inside the <BODY> tags. This file does NOT contain the <BODY> tags or anything that would go above them. The first thing in this file is the <table>…. form code…

EditView.html is the layout for a form and I have a field, 3 checkboxes, and a label.
Here is the code for each of them.
Field:
<td class=”dataField”><slot><input name=’amount’ id=’amount’ tabindex=’5′ size=’6′ maxlength=’10’ type=”text” value='{AMOUNT}’></slot><FONT COLOR=”#666666″ SIZE=”1″>(Per Month)</FONT></td>

Checkboxes have code:
<td class=”dataField”><slot><input name=’dti’ class=”checkbox” type=”checkbox” tabindex=”16″ id=’dti’ onclick=”updateTotal(this, 10.00)” {DTI}><FONT COLOR=”#666666″ SIZE=”1″>($10)</FONT></slot></td>

Label:
<td class=”dataField”><slot><div id=”totalLabel”>0.00</div></slot></td>

The field (amount) is populated with a value (AMOUNT) which comes from a related php file. That php file gets the value from a mySQL DB. The amount value is a dollar amount lets say 10 in this case.
Each of the checkboxes has a dollar amount associated with them. Above the dti checkbox has a value of 10 associated to it.

What I want to happen is when the form loads the label displays the current dollar value, which would be the value of amount plus the dollar values of any of the checkboxes if they are checked. Then after the page is loaded when a user clicks on a checkbox, let say dti, the label updates on the fly and displays the new value.

I have created a javascript that updates the label on the fly when a user checks one of the checkboxes, but the problem is the value is not initialized to the begining value when the page loads. Thus the label always starts with a value of 0. So right now when the page loads the user sees the amount field with a value of 10, they see the dti checkbox checked which they know adds 10 more dollars.. Thus my label should display 20 but it has 0. Then when a user unchecks the dti checkbox the value of the label displays -10.

If I could just figure out how to start the value of the label at the correst startValue when the page loads everything should work.

Here is the java script that I have put at the top of the page above the <table> tag:
<script type=”text/javascript”>
var total = new Number(0.00);

function updateTotal(cb, amount) {
if (cb.checked) {
total += amount;
} else {
total -= amount;
}

var label = document.getElementById(“totalLabel”);
label.innerHTML = total.toFixed(2);
}

</script>

I hope I explained this well. PLEASE Help… I dont know javascript very well. Someone suggested offhand to me to wrap the AMOUNT value in a <span> tag but I dont see how to do that when the value is assigned inside of the <input> tag..

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Barakanooz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...