0

I have this JavaScript code how can i display the return value in a text box or in a label?

  <script>
     function getSelectedProjectID() {
            var BalanceDue = @Model.BalanceDue;
            return {
                id: ProjectID
            }
        }
    </script>
5
  • 1
    This isn't valid javascript, can you post a minimal reproducible example? Commented Apr 3, 2020 at 0:20
  • $("#labelId").val(getSelectedProjectID().id) Commented Apr 3, 2020 at 0:22
  • @freedomn-m i have this <label for="currency">Balance Due:</label>? Commented Apr 3, 2020 at 0:26
  • @SuperStormer I enclose in the <script></script> that's how i have it Commented Apr 3, 2020 at 0:30
  • You probably want to adjust your tags. It has nothing to do with JQuery or C#. You probably want to add ASP.NET Commented Apr 3, 2020 at 0:41

2 Answers 2

1

you can assign your label an id

<label id="labelId"></label> 

, and then just return function content to this label textConent:

 document.getElementById("labelId").textContent = getSelectedProjectID();
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using vanilla JS, you could do :

let labels = document.getElementsByTagName('label');
for (var i = 0; i < labels.length; i++) {
if (labels[i].htmlFor == 'currency') {
     label.innerHTML = getSelectedProjectID().id;        
    }
}

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.