user3709813
user3709813

Reputation: 119

Setting value of a parameter in html by calling javascript function

Is there a way to do this? <'param name = "ticket" value = "getTicket()">

getTicket() is my Javascript function. Whatever the function returns, that should be the value of the parameter tag.

I cant set it explicitly using Javascript "document.getElem...." because I want the value to be loaded at the time of page load. Or, while the parameter is being set.

For further info, I am trying to do this for Tableau Trusted Authentication.

Upvotes: 0

Views: 2186

Answers (4)

Phuoc Do
Phuoc Do

Reputation: 1344

You can use jquery $(document).ready() function callback. If jquery isn't available, then you can use the equivalence of it.

$(document).ready equivalent without jQuery

Then you can access document.getElement.

Upvotes: 0

Rafael dAS
Rafael dAS

Reputation: 119

Are you using server-side scripting?

Isn't more effectively to do what you do using the request/response ways?

Like directly using <%=ticketValue%> (ASP way) or ${ticketValue} (JSP way)?

Upvotes: 1

raidendev
raidendev

Reputation: 2809

You can access node from JavaScript right after it was created. You're not obligated to wait for DOMContentLoaded event. So this code will work as expected:

<script>
  function getTicket() {
    return 'whatever';
  }
</script>

<param name="ticket" value="" class="js-ticket">
<script>
  var ticket = document.querySelector('.js-ticket');
  ticket.value = getTicket();

  console.log(ticket);
</script>

See demo.

This approach is better than using document.write, see good explanation.

Upvotes: 0

mrida
mrida

Reputation: 1157

You may use Document.Write as follows:

<'param name = "ticket" value = "<script>
document.write(getTicket());
</script>">

Upvotes: 0

Related Questions