/    Sign up×
Community /Pin to ProfileBookmark

Getting the Sum of Two Variables

I would like to multiply combo_1 and combo_2 to give an outcome and display it in the textbox of txt_price using javascript.

f[‘txt_price’].value = (f[‘combo_1’].value).toFixed(2);

This is something I was working on but no results so far. Any help would be greaty appreciated.

<form>
<select name=”combo0″ id=”combo_0″ onChange=”change(this);” style=”width:200px;”>
<option value=”0″>-select-</option>
<option value=”1″>Canada</option>
<option value=”2″>States</option>

</select>
<BR><BR>

<!– I would like to Multiply this field –>
<select name=”combo1″ id=”combo_1″ onChange=”change(this)” style=”width:200px;”>
<option value=”1″></option>
</select>
<label></label>
<BR>
<BR>

<!– and this field –>
<select name=”combo2″ id=”combo_2″ onChange=”change(this);” style=”width:200px;”>
<option value=”1″></option>
</select>
<BR>
<br>

<!– To present an outcome to this field –>
<input type=”text” name=”txtPrice” id=”txt_price” onChange=”change(this);” style=”width:200px;”>
<BR>
</form>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@WayniacauthorMay 24.2009 — Issue resolved, that you very much. Here is the working code.

<select name="combo1" id="combo_1" style="width:200px;">

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

</select>

<label></label>

<BR>

<BR>



<!-- and this field -->

<select name="combo2" id="combo_2" style="width:200px;">

<option value="1">1</option>

<option value="5">5</option>

</select>

<BR>

<br>



<!-- To present an outcome to this field -->

<input type="text" name="txtPrice" id="txt_price" style="width:200px;">

<BR>

</form>



<script type="text/javascript">

// avoid using inline script like onclick and onchange, bad practice.

window.onload = function() {

var dropChange = function() {

var v1 = document.getElementById("combo_1").value, v2 = document.getElementById("combo_2").value;

document.getElementById("txt_price").value = v1 * v2;

};



document.getElementById("combo_1").onchange = dropChange;

document.getElementById("combo_2").onchange = dropChange;


};
×

Success!

Help @Wayniac 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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