kelak shan
kelak shan

Reputation: 19

how to in set javascript id in input value

i want to inset my javascript id in to the place of input value .

if i give Interest name input value="100"

how can i get tc named table input value="75"

my input form

    <tr>
                            <th>Loan Amount</th>
                            <th>INTEREST RATE %</th>
    <tr>              
            <tbody>
<td><input disabled type="" name="tc" id="int_amount" class="formcontrol"value=""/></td>
<td><input  type="number" name="Interest" id="input2" onkeyup="calculate();"/ class="form-control" value=""/></td>

            </tr>
            </tbody>

javascript

var vatti = document.pricecal.Interest.value;
var Total = vatti -25;

    if(vatti = null)
    {

        document.getElementById("int_amount").innerHTML  = "Rs:"+" "+Total;

    }
[want out put like this][1]

Upvotes: 0

Views: 51

Answers (3)

A. Iglesias
A. Iglesias

Reputation: 2675

HTML:

<tbody>
  <tr>
    <td><input type="number" name="Interest" id="input2" class="form-control" value=""/></td>
    <td><input type="" name="tc" id="int_amount" class="formcontrol" value=""/></td>
  </tr>
</tbody>

Javascript:

document.getElementById('input2').onkeyup = function() {
    document.getElementById('int_amount').value = (this.value != '') ? 'Rs: ' + (parseInt(this.value)-25) : '';
}

Upvotes: 0

guest271314
guest271314

Reputation: 1

Set the .value of the <input> element, not the .innerHTML

document.getElementById("int_amount").value  = "Rs:"+" "+Total;

Upvotes: 0

PraveenKumar
PraveenKumar

Reputation: 1861

Hope this helps you.

function calculate(interest){
  var vatti = interest.value;
  if (vatti != '') {
    var Total = vatti - 25;
      document.getElementById("int_amount").value = Total;
  }else{
    document.getElementById("int_amount").value = '';
  }
}
<table>
    <tbody>
	<tr>
	    <td><input type="number" name="Interest" id="input2" onkeyup="calculate(this)" onchange="calculate(this)" class="form-control" value=""/></td>
	    <td><input type="" name="tc" id="int_amount" class="formcontrol" value=""/></td>
	</tr>
    </tbody>
</table>

Upvotes: 1

Related Questions