AHMED SAMY
asked on
small help
i am not good in java
i have this code
i need to insert one value in the first input and auto calculate in the second and third input
<input type="text" name="markup" id="markup">
<input type="text" name="mark" id="mark">
<input type="text" name="marknet" id="marknet">
<script type="text/javascript" src="js/jquery.js"></scrip t>
<script type="text/javascript">
$(document).ready(function (){
var item1=$("#markup").val() / 100 ;
var item2=$("#mark").val();
var item3=item1 * item2;
var item4=item3 + item2;
$("#markup").change(functi on(){
$("#mark").val(item3);
$("$marknet").val(item4);
});
});
</script>
i have this code
i need to insert one value in the first input and auto calculate in the second and third input
<input type="text" name="markup" id="markup">
<input type="text" name="mark" id="mark">
<input type="text" name="marknet" id="marknet">
<script type="text/javascript" src="js/jquery.js"></scrip
<script type="text/javascript">
$(document).ready(function
var item1=$("#markup").val() / 100 ;
var item2=$("#mark").val();
var item3=item1 * item2;
var item4=item3 + item2;
$("#markup").change(functi
$("#mark").val(item3);
$("$marknet").val(item4);
});
});
</script>
Posting JavaScript questions in the Java TA is not appropriate, and might make your question less likely to be answered. http://technojeeves.com/joomla/index.php/free/127-javascript-is-not-java
I didn't check the whole thing, this however :
$("$marknet").val(item4);
should be :$("#marknet").val(item4);
ASKER
i changed to it
please small help
result is NaN
please small help
<input type="text" name="markup" id="markup">
<input type="text" name="mark" id="mark">
<input type="text" name="marknet" id="marknet">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var item1=parseInt($("#markup").val()) / 100 ;
var item2=parseInt($("#mark").val());
var item3=item1 * item2;
var item4=item3 + item2;
$("#markup").change(function(){
$("#mark").val(item3);
$("#marknet").val(item4);
});
});
</script>
result is NaN
Well, Ahmed, the values you are attempting to set for items1, item2 are not initially set on documentLoad.
Give them an initial value in the HTML and you won't get the NaN:
If you are supposed to be waiting to calculate the value, you should set item1-item4 in the .change. Can you try to explain a little better what you are trying to do here?
Give them an initial value in the HTML and you won't get the NaN:
<input type="text" name="markup" id="markup" value="100">
<input type="text" name="mark" id="mark" value="20">
<input type="text" name="marknet" id="marknet">
If you are supposed to be waiting to calculate the value, you should set item1-item4 in the .change. Can you try to explain a little better what you are trying to do here?
and you should put the calculation of your variables into the change event, else they will always stay static!
to handle NaN error, you could use isNaN in your codes:
to handle NaN error, you could use isNaN in your codes:
<script type="text/javascript">
$(document).ready(function () {
$("#markup").change(function () {
var item1 = parseInt(isNaN($("#markup").val()) ? 0 : $("#markup").val()) / 100;
var item2 = parseInt(isNaN($("#mark").val()) ? 0 : $("#mark").val());
var item3 = item1 * item2;
var item4 = item3 + item2;
$("#mark").val(item3);
$("#marknet").val(item4);
});
});
</script>
ASKER
thanks to all
this code is working dunamic but syntax to change this numbers to varaible is wrong
how i can put this values from input to item1 and item2
this code is working dunamic but syntax to change this numbers to varaible is wrong
<input type="text" name="markup" id="markup">
<input type="text" name="mark" id="mark">
<input type="text" name="marknet" id="marknet">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#markup").change(function(){
var x= 100;
var item1=200/ x ;
var item2=300;
var item3=item1 * item2;
var item4=item3 + item2;
$("#marknet").val(item4);
});
});
</script>
how i can put this values from input to item1 and item2
The same way you initially did it:
var item1=parseInt($("#markup").val()) / x ;
var item2=parseInt($("#mark").val());
ASKER
not working i tried it
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i see it works right thanks
good work
good work