1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Web Design & Development' started by sepala, Sep 16, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. sepala

    sepala Thread Starter

    Joined:
    May 20, 2010
    Messages:
    4,038
    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.
     
  2. andythepandy

    andythepandy

    Joined:
    Jul 2, 2006
    Messages:
    367
    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
     
  3. sepala

    sepala Thread Starter

    Joined:
    May 20, 2010
    Messages:
    4,038
    wow..wow...wow...Thanks again and again and again Andy..It solved one of my major problems..
     
As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/950277