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"></script>
<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(function(){
                  $("#mark").val(item3);
                  $("$marknet").val(item4);
            });
      });
</script>
AHMED SAMYownerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
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
0
M. TariqApplication DeveloperCommented:
I didn't check the whole thing, this however :
$("$marknet").val(item4);

Open in new window

should be :
$("#marknet").val(item4);

Open in new window

0
AHMED SAMYownerAuthor Commented:
i changed to it

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>								

					

Open in new window



result is NaN
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Eddie ShipmanAll-around developerCommented:
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:
<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">

Open in new window


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?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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:

<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>

Open in new window

0
AHMED SAMYownerAuthor Commented:
thanks to all
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>	

Open in new window


how i can put this values from input to item1 and item2
0
Eddie ShipmanAll-around developerCommented:
The same way you initially did it:
var item1=parseInt($("#markup").val()) / x ;
var item2=parseInt($("#mark").val());

Open in new window

0
AHMED SAMYownerAuthor Commented:
not working i tried it
0
Eddie ShipmanAll-around developerCommented:
Look, the problem is, you are trying to use the value from $("#mark") when it HAS NO VALUE. If you give it a value OR change the .change handler to only fire when it is changed then it will work.

This is setting a value for the mark input:
<input type="text" name="markup" id="markup">
<input type="text" name="mark" id="mark" value="300">
<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=parseInt($("#markup").val()) / x ;
            var item2=parseInt($("#mark").val());
            var item3=item1 * item2;
            var item4=item3 + item2;
            
            $("#marknet").val(item4);
        });
    });
</script>

Open in new window

This is changing the handler:
<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(){
        $("#mark").change(function(){
            var x= 100;
            var item1=parseInt($("#markup").val()) / x ;
            var item2=parseInt($("#mark").val());
            var item3=item1 * item2;
            var item4=item3 + item2;
            
            $("#marknet").val(item4);
        });
    });
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AHMED SAMYownerAuthor Commented:
i see it works right thanks

good work
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.