Question: ```
<input type="text" name="weight" id="weight" class="form-control input-sm" placeholder="Weight" value="<div id="variable"></div>">

```

I have this code. I want the value from "weight" to get the content of `<div id="variable"></div>` which is generated with jquery. It is a number like 82 for example.

How can I do that?

I've tried with strip\_tags from php but when doing that, it also stopping the thing to work because it is removing `<div id="variable"></div>`.

When I click calculate in the window, it will generate "159". I want 159 to be added as value in my weight input.

[![enter image description here](https://i.stack.imgur.com/ATNK5.jpg)](https://i.stack.imgur.com/ATNK5.jpg)

The value inside `<div id="variable"></div>` is dynamically generated from a previous jquery code. So `<div id="variable"></div>` starts as `<div id="variable"></div>`, with no value

Answer: 
Do it from the dom after page loads by getting that text and passing it to input value

```js
$(function(){
  $('#weight').val( $('#variable').text().trim() )
})
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="weight" id="weight" class="form-control input-sm" placeholder="Weight" >
<div id="variable">82</div>
```
Try using jQuery to set value in the textbox:

Code
====

```
$('#weight').val($('#variable').html());

```