Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7075123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:08:23+00:00 2026-05-28T06:08:23+00:00

i have my code(html/javascript) here which allows user to input the size and color

  • 0

i have my code(html/javascript) here which allows user to input the size and color of the square.The problem is when i click the go button the textfields disappear including the button and the one that displays is the output.Is there any ways that i could retain the textfields and the button then output the square below it?


<html>
<head>
<script type="text/javascript">
size=0;
function display(form){
    size=form.inputbox.value;
    color=form.inputbox2.value;
    for(i=0;i<size;i++){
            for(j=0;j<size;j++){
                if(i==0||i==(size-1)){
                        document.write("<font color="+color+">*&nbsp;");
                    }
                else if (j == 0||j == (size-1)) {
                        document.write("*&nbsp;");
                    }
                else {
                        document.write("&nbsp;&nbsp;&nbsp;");
                    }
            }
                    document.write("<br>");
        }

}
</script>
</head>
<body>
    <form name="form1" action="" method="get">
    Input size of the square:
        <input type="text" name="inputbox" value=""><br>
    Input color of the square:
        <input type="text" name="inputbox2" value="">

    <input type="button" name="button" value="Go" onClick="display(this.form)">
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:08:24+00:00Added an answer on May 28, 2026 at 6:08 am

    Calling document.write on a page that has completed rendering will destroy the exiting DOM document on the page, replacing it with only the newly written HTML elements.

    If you wish to add to existing DOM elements, select an element and write to its innerHTML property instead.

    <html>
    <head>
    <script type="text/javascript">
    size=0;
    function display(form){
        size=form.inputbox.value;
        color=form.inputbox2.value;
    
        // A node to write into
        writeTo = document.getElementById('writeTo');
    
        for(i=0;i<size;i++){
                for(j=0;j<size;j++){
                    if(i==0||i==(size-1)){
                            writeTo.innerHTML = writeTo.innerHTML + "<font color="+color+">*&nbsp;";
                        }
                    else if (j == 0||j == (size-1)) {
                            writeTo.innerHTML = writeTo.innerHTML + "*&nbsp;";
                        }
                    else {
                            writeTo.innerHTML = writeTo.innerHTML + "&nbsp;&nbsp;&nbsp;";
                        }
                }
                        writeTo.innerHTML = writeTo.innerHTML + "<br>";
            }
    
    }
    </script>
    </head>
    <body>
        <form name="form1" action="" method="get">
        Input size of the square:
            <input type="text" name="inputbox" value=""><br>
        Input color of the square:
            <input type="text" name="inputbox2" value="">
    
        <input type="button" name="button" value="Go" onClick="display(this.form)">
        </form>
        <div id='writeTo'></div>
    </body>
    </html>
    

    And add an empty node to your HTML something like:

    <div id='writeTo'></div>
    

    Here it is in action on jsFiddle.net

    To get the square to be all the correct color, it is easiest to change the CSS color property of <div id='writeTo'>

    document.getElementById('writeTo').style.color = color;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have javascript code embedded inside a html template file. When I load this
I have a dialog box, created with the code javascript and HTML generated below.
I have this function in my Javascript Code that updates html fields with their
I have the following code in JavaScript and jQuery: $(<li />) .html('Some HTML') I
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
The JavaScript code window.print() can print the current HTML page. If I have a
Im working on a simple html/javascript multiplication game, in which I have a multiplication
I have a code which works very nice and I had great help here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.