# Solved: javascript:How to take the output in the same page?



## sepala (May 20, 2010)

have a look at the following code

This code takes the user input and generates a marquee. But the case is it generates the marquee in a separated page, but I need it to generated in the same page where that textfield and button exists, below to them. Can anyone tell me how to do that? Please help. Any help would be much appreciated.


----------



## andythepandy (Jul 2, 2006)

The problem is that if document.write is called after the page has loaded, like in you case, then it overwrites the whole page - not what you intended

Instead you could do the following:

```
<html >
<head>
<script language="javascript">
function texter()
{
var textField;
textField = txtone.value;
textFieldLength = txtone.value.length;

if (textFieldLength==0)
{
txtone.value=prompt("Please enter someting","");
}
else
{ 
result.innerHTML = "<marquee>"+"welcome "+"<font color = 'red'>"+textField+"</font>"+" how are you?"+"</marquee>";
}

}



</script>
</head>

<body>
<input type = "text" id = "txtone" >
<input type= "button" value = "click" onclick = "texter()">
<div id="result"></div>
</body>
</html>
```
That writes the marquee to a div that already exists using the innerHTML attribute eliminating the need for document.write

Hope that helps

Andy


----------



## sepala (May 20, 2010)

wow..wow...wow...Thanks again and again and again Andy..It solved one of my major problems..


----------

