Question: I am not sure if this is possible, but I am getting a variable after some text input from the user. This variable is obtained in Javascript, but I need it later in the HTML body tag of my code. Is there a way to do this?

This is the Javascript code:

```
<script type="text/javascript">
 window.alert("Documento ha sido adjuntado!")
 <!--
 var name = prompt("Referencia del Documento: ", "");
 //-->
 window.close();
 </script>

```

Answer: 
You could include a hidden element within your page and set the value you need within the hidden value, then when you need to reuse it, just reference the hidden field.

[**Working Example (Uses a textbox as opposed to a hidden field for viewing purposes)**](http://jsfiddle.net/FDRZS/)

**HTML:**

```
<input type="hidden" id="nameValue" />

```

**Javascript:**

```
 <script type="text/javascript">

 window.alert("Documento ha sido adjuntado!")

 var name = prompt("Referencia del Documento: ", "");

 //Sets the hidden value with "name"
 document.getElementById('nameValue').value= name;

 window.close();
 </script>

```

**As per your specific question:**

```
 <script type="text/javascript">

 window.alert("Documento ha sido adjuntado!")
 var name = prompt("Referencia del Documento: ", "");
 window.close();
 UpdateDatabase(name);

 function UpdateDatabase(yourString)
 {
     //Servlet call to Update Database with "yourString"
 }

 </script>

```
Try using JavaScript to update the HTML element after you prompt for the value. 

```
 var name = prompt();
 document.getElementById("MyElement").value = name;

<input type='text' id="MyElement" />

```