Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

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


(!)

sepala's Avatar
Computer Specs
Member with 4,038 posts.
THREAD STARTER
 
Join Date: May 2010
Location: Sri Lanka
Experience: Advanced
16-Sep-2010, 02:33 AM #1
Solved: javascript:How to take the output in the same page?
have a look at the following code


<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
{
document.write("<marquee>"+"welcome "+"<font color = 'red'>"+textField+"</font>"+" how are you?"+"</marquee>");
}

}



</script>
</head>

<body>
<input type = "text" name = "txtone" >
<input type= "button" value = "click" onclick = "texter()">
</body>
</html>

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's Avatar
andythepandy andythepandy is offline
Computer Specs
Member with 367 posts.
 
Join Date: Jul 2006
Location: England
Experience: Intermediate to Advanced
16-Sep-2010, 09:57 AM #2
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:
Code:
<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's Avatar
Computer Specs
Member with 4,038 posts.
THREAD STARTER
 
Join Date: May 2010
Location: Sri Lanka
Experience: Advanced
17-Sep-2010, 01:33 AM #3
wow..wow...wow...Thanks again and again and again Andy..It solved one of my major problems..
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
javascript:How to take the output in the same page? sepala Web Design & Development 0 16-Sep-2010 02:29 AM
On my other laptop it doesnt go to the log in page where I have to type my password dilaksan Windows XP 86 05-Aug-2010 06:29 PM
How do you change *.URL icon to the icon in the same folder? Xangel Tech Tips and Reviews 3 04-Jan-2008 01:00 AM
Want to open hyperlink window in the same *.doc window berniejay Windows XP 0 24-Jun-2007 11:47 PM
How can i move adsl connection to our another flat in the same building? WebTeam4U Networking 7 12-Jan-2005 08:38 PM

WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑