0

I need to create a jsp form with javascript. The problem is to assign the data path.

Imagine $form.work = "Hello Work";

If I create the form with html:

<div id='workForm'> Work:<input value=${form.work}></input> </div>

The input will show the work value (Hello Work). But I need to create this div form with js, something like:

var oDiv = document.createElement('div');
oDiv.setAttributte('id', 'workForm');
var oInput= document.createElement('input');
oDiv.appendChild(oInput)
...

I tryed to add an attribute to the input like:

oInput.addAttributte('value', '${form.work}')

But it shows: ${form.work} not Hello Work

Can someone help me?

Thanks!

1

2 Answers 2

1

Try this,

var work = "<%=form.work%>"; 

or

var work = "${form.work}"
alert(work);

If the window/ System alert had provided what you need, then you can setAttribute("value", work) to the hidden field or the JSP element you needed.

Sign up to request clarification or add additional context in comments.

Comments

0

You're close, you must use template literals (backticks) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

oInput.setAttribute('value', `${form.work}`)

1 Comment

I tryed but i got a undefined message

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.