Type Conversion problem when passing through javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WebJag
    New Member
    • Jan 2012
    • 1

    Type Conversion problem when passing through javascript

    Hi,
    I have tried this solution (http://bytes.com/topic/javascript/an...g-numbers-form) for new html file, which works fine, however when I use same code in file where I have several Div's one inside another, it do not call/take the numbers. Please let me know if you if I call the textbox values with reference to form_name or div_name.....


    Code:
    <body Background ="Images/SoftBlue.jpg"> 
    <div id="container">
    <form name="umsForm" action="MonthlysalUpdate.php" method="POST">
     <!-- ..................__>
    <div id="saldetails">
    			<table class="center">
    			<tr><td>Earnings :</td><td>Amount</td><td width = "20"></td><td>Deductions</td><td>Amount</td></tr>
    			
    			<tr><td>Basic :</td><td>		<input type="text" name="basic" onchange="calculate();" value=<?php echo $basic; ?>></td><td width = "20"></td><td>GPF/NPS :</td><td><input type="text" name="basic" value=<?php echo $basic; ?>></td></tr>
    			
    			<tr><td>Grade Pay :</td><td>	<input type="text" name="grade_pay" onchange="calculate();" value=<?php echo $gpay;?> ></td><td width = "20"></td><td>CGEIS :</td><td><input type="text" name="basic" value=<?php echo $row['ccc'];?>></td></tr>
    			
    			<tr><td>Special Pay :</td><td>	<input type="text" name="special_pay" onchange="calculate();"  value=<?php echo $special_pay;?> ></td><td width = "20"></td><td>CGHS :</td><td><input type="text" name="basic" value=<?php echo $row['cid'];?>></td></tr>
    
    <tr><td>Gross Earnings :</td><td><strong><input type="text" name="gross_earnings" disabled="disabled" value=<?php echo $total; ?> ></strong></td><td width = "20"></td><td>Gorss Deductions :</td><td><strong><input type="text" name="basic" disabled="disabled" value=<?php echo $basic; ?>></strong></td></tr>
    
    </div>
    </div>
    </form>
    </body>
    Here is the javascript

    Code:
    <script>
    			function calculate(){
    				alert(document.umsForm.basic.value);
    				document.umsForm.gross_earnings.value = eval(document.umsForm.basic.value) + eval(document.umsForm.gpay.value) + .......;
    			}		
    		</script>
    Thanks,
    Jag
    Last edited by acoder; Jan 27 '12, 12:09 PM. Reason: Added [code] tags + added link back to thread
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Do you get an error?

    Change eval to parseInt().

    PS. split off your question from the thread you posted in (linked to in your post) - please post new questions in a separate thread.

    Comment

    Working...