Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  70] [ 5]  / answers: 1 / hits: 65806  / 13 Years ago, tue, october 18, 2011, 12:00:00

Let's say I have this HTML:



<select id='list'>
<option value='1'>First</option>
<option value='2'>Second</option>
<option value='3'>Third </option>
</select>
<input type =text id=text/>


and then this JavaScript



 //other variables are also declared here
var x1 = 5;
var x2 = 10;
var value = x1 * x2;
var list_value =$(#list).change(function() {
$(this).val();
// just an example of how i want the function in the variable
});
var nwval = value * list_value;
$('#text').val(nwval);
// some long piece of code
// i'm also using the list_value value somewhere in the long piece of code..


I want the val in the textbox to change as the user selects an option, I know it'll work if I wrap the change event around it, but is there any way to go about this while keeping it as that variable list_value?


More From » jquery

 Answers
109
var x1 = 5;
var x2 = 10;
var value = x1 * x2;
var nwval;
$(#list).change(function() {
nwval = value * $(this).val();
$('#text').val(nwval);
});

[#89558] Monday, October 17, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jocelynkarsynr

Total Points: 472
Total Questions: 98
Total Answers: 96

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
jocelynkarsynr questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Sat, Jul 11, 20, 00:00, 4 Years ago
Sun, May 10, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
;