topcat3
topcat3

Reputation: 2642

jquery javascript passing value to html page

I have the following value 'testValue' in my javascript file

$('#testValue').val(RestServices.getValueCovid(response, 'TESTVALUE'));

In the html file I have

<input name="testValue" id="testValue" />

This works and displays the value on the webpage but it is in an input box.

I want to display it just as plain text using <p> <span> <div> or whatever you suggest. The browser is IE8. I have tried getElementById and a few other ways but not working. Any suggestions welcome

Upvotes: 0

Views: 46

Answers (1)

David
David

Reputation: 218960

First create your page element, for example:

<span id="testValueText"></span>

Then set the text of that element much in the same way you set the value of the <input>:

$('#testValueText').text(RestServices.getValueCovid(response, 'TESTVALUE'));

A couple notes:

  1. The id doesn't have to be what I specified here, it just has to be unique. If you're getting rid of the <input> element then you can re-use the same id to make it simpler.
  2. If you're using both elements then instead of fetching the value from RestServices twice, just fetch it once and store it in a variable. Then use that variable to populate the two elements.

Upvotes: 1

Related Questions