0

Sorry if this is a repeated question but I could not figure out to word this any better to perform a search. To further explain, I have a few disabled inputs with default values, pretty much inputs to display text. I have chose this method instead of just using <p> etc because I am making this for a client and would like to maybe in the future enable these fields to make them editable. Anyways, after calculating some data in javascript, the value of these input fields are changed (through javascript of course) but do not update the value on the screen. The value is updating because the calculations are coming out correctly, the HTML part is not updating however. If I need to explain more please comment, but below I will post the HTML and javascript code.

EDIT

To best describe this, here is an example of how my HTML appears in the web browser: Inverter Service Fees $ 0.00 When I call the javascript function it changes the value of the input but the web browser still displays Inverter Service Fees $ 0.00 where I want it to display Inverter Service Fees $ (updated value) Hope this makes more sense!

HTML

<tr>
  <td>Inverter Service Fees <i class='fa fa-info-circle fa-lg' title='Labor and gas are included.'></i></td>
  <td align='right'>$ <input  id='inputServiceFees' value='0.00' disabled></td>
</tr>

Javascript

inputServiceFees = parseFloat(document.getElementById('inputServiceFees').value, 10);

inputServiceFees = varServiceFees;
inputServiceFees.value = varServiceFees;
inputServiceFees.innerHTML = varServiceFees;
2
  • Can you describe the HTML part? You mean the DOM or initial HTML sent to client? Commented Mar 17, 2014 at 4:03
  • @alex I updated the OP, I am pretty much using the value field on the input as a way to display text on the web page. I just want this 'text' so to speak, to change when the value of that field is updated. Commented Mar 17, 2014 at 4:08

3 Answers 3

3

I am not sure if you deliberately left out part of your javascript but it could look something like this to work:

document.getElementById('inputServiceFees').value = varServiceFees;
Sign up to request clarification or add additional context in comments.

1 Comment

Using this line worked and I thank you for that, but one more question if you don't mind: Is it necessary to use parsefloat() around the code given if these are always numbers? I used parsefloat on previous inputs that were not disabled but using parsefloat was the reason this was not working. If that makes no sense at all then ignore it aha because you already answered my question. Thanks again!
1

@tuberider is correct you have missed to add document.getElementById('inputServiceFees').value

Try the code below

Javascript Code

<script>
 var varServiceFees = 3029;
 document.getElementById('inputServiceFees').value = varServiceFees;
</script>

HTML Code

<tr>
  <td>Inverter Service Fees <i class='fa fa-info-circle fa-lg' title='Labor and gas are included.'></i></td>
  <td align='right'>$ <input  id='inputServiceFees' value='0.00' disabled></td>
</tr>

Comments

1

For input tag you can set the value using 2 ways . getElementById or getElementByName.

For you can Try this, because you have used id as attribute:-

<script>
document.getElementById('inputServiceFees').value=varServiceFees;
<script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.