/    Sign up×
Community /Pin to ProfileBookmark

javascript select dropdown and calculations in an array

[code=html]
<script language=”Javascript” type=”text/javascript”>
function DisplayCourseFee (CourseFeePair) {
var currency_change = CourseFeePair.split(‘|’);
var payamount = document.getElementById(‘add_value’).value; // (user input pay amount)
var inrvalue = document.getElementById(‘inrvalue’).value; // (user input pay amount)

document.getElementById(‘rate’).value = currency_change[1]; //(display course fee when item is selected)
}
function CalculateFee () {
var currency_change = document.getElementById(‘rate’).value;
var payamount = document.getElementById(‘add_value’).value; // (user input pay amount)
var inrvalue = document.getElementById(‘inrvalue’).value; // (user input pay amount)

//var balfee = (payamount*1) / (currency_change*1);
var balfee = (inrvalue*payamount) / (currency_change*1);

//var balfee = (CourseFee*1) / (payamount*1);
// Used desired display of following commands
document.getElementById(‘Balance’).value = balfee; // (display course fee when item is selected)
}
</script>
<form name=”myForm” id=”myForm”>
<table><tr>
<td><select id=’currency_change’ onchange=’DisplayCourseFee(this.value)’><option value=USD|1>USD</option><option value=INR|64.050649>INR</option><option value=GBP|0.647726>GBP</option><option value=EUR|0.908714>EUR</option><option value=SGD|1.355678>SGD</option><option value=AUD|1.348929>AUD</option><option value=CAD|1.27195>CAD</option><option value=CHF|0.945799>CHF</option><option value=JPY|122.1226>JPY</option><option value=MYR|3.810291>MYR</option><option value=ZAR|12.46153>ZAR</option></select>
</td>
<td><input type=”text” id=”inrvalue” name=”inrvalue” value=”64.050649″></td>
<td><input name=”rate” type=”text” id=”rate” size=”6″></td>

<div id=”Diploma” style=”font-style:italics”></div>
<td>Pay amount: <input name=”add_value” type=”text” id=”add_value[]” value=”” onChange=”CalculateFee()”> </td><!– // (user input pay amount) –>
<td>Balance:
<input name=”txtbal” type=”text” id=”Balance” value=”2000″ readonly></input>
</td>
</tr>

<tr>
<td><select id=’currency_change’ onchange=’DisplayCourseFee(this.value)’><option value=USD|1>USD</option><option value=INR|64.050649>INR</option><option value=GBP|0.647726>GBP</option><option value=EUR|0.908714>EUR</option><option value=SGD|1.355678>SGD</option><option value=AUD|1.348929>AUD</option><option value=CAD|1.27195>CAD</option><option value=CHF|0.945799>CHF</option><option value=JPY|122.1226>JPY</option><option value=MYR|3.810291>MYR</option><option value=ZAR|12.46153>ZAR</option></select>
</td>
<td><input type=”text” id=”inrvalue” name=”inrvalue” value=”64.050649″></td>
<td><input name=”rate” type=”text” id=”rate” size=”6″></td>

<div id=”Diploma” style=”font-style:italics”></div>
<td>Pay amount: <input name=”add_value” type=”text” id=”add_value” value=”” onChange=”CalculateFee()”> </td><!– // (user input pay amount) –>
<td>Balance:
<input name=”txtbal” type=”text” id=”Balance” value=”2000″ readonly></input>
</td>
</tr>

</p>
</tr></table>
</form>

[/code]

The javascript is working fine. But how i will i do the same script with arrays []…? say currency_change drop down with an array currency_change[]…all the fields are coming from a php loop. Is there any solution?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumAug 03.2015 — I'm not shure whether I understand you correctly: You want to have an array and create the options of the select automatically based on this array?

What would be the benefit of this? If you do it in a loop in PHP it's no problem to create the options explicitly?
Copy linkTweet thisAlerts:
@jedaisoulAug 03.2015 — It's a bit pointless giving us the code that is working. A link would suffice for that. We'd rather see your attempt at amending the code, and the problems with that...
×

Success!

Help @sujithgnair 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...