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

  • Home
  • SEARCH
  • 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 4329274
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:48:07+00:00 2026-05-21T09:48:07+00:00

I’m making a UNIX web-based terminal for learning purposes. So far I have made

  • 0

I’m making a UNIX web-based terminal for learning purposes. So far I have made a text box and the output is being displayed. Sort of like this.

<?php
$output = shell_exec('ls');
echo "<pre>$output</pre>";
?>

Form

<html>
<head>
<link href="/css/webterminal.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function shell_execute(str)
{
if (str.length==0)
  {
  document.getElementById("txtOut").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtOut").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","exec.php?q="+str,true);
xmlhttp.send();
}
</script>
</head
<body onLoad="setUser();">
    <div class="container">

    <h2>UNIX Web Based Terminal 1.0</h2>
        <br />
    <p><b>output</b></p>
<form>
<span id="User"></span>< <input type="text" class="textbox" onkeyup="shell_execute(this.value)" size="20" />
</form>
<div class="output">
<p><span id="txtOut"></span></p>

    </div>
</div>
</body>
</html>

But I want it to look as if the page was really a terminal. When I type a command, it should store the result of the shell command, and then append it to a div tag. So as I am typing in commands, it will keep on showing the output. Just like in the UNIX terminal.

How can I append the output of the commands to a div tag?

  • 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-21T09:48:08+00:00Added an answer on May 21, 2026 at 9:48 am

    change:

    document.getElementById("txtOut").innerHTML=xmlhttp.responseText;
    

    to:

    document.getElementById("txtOut").innerHTML += xmlhttp.responseText;
    

    On a sidenote, why are you not using any of the well established javascript frameworks?

    With jQuery for example you could reduce your code to maybe 4 lines.

    Edit – using jQuery:
    http://api.jquery.com/jQuery.ajax/

    <html>
        <head>
            <link href="/css/webterminal.css" rel="stylesheet" type="text/css" />
            <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
            <script type="text/javascript">
                $(function () {
                    $('#cmd').bind('keydown', function (evt) {
                        if (evt.keyCode === 13) { // enter key
                            var cmdStr = $(this).val();
    
                            $.ajax({
                                url: 'exec.php',
                                dataType: 'text',
                                data: {
                                    q: cmdStr
                                },
                                success: function (response) {
                                    $('#txtOut').append(response);
                                }
                            });
                        }
                    });
                });
            </script>
        </head>
    
        <body>
            <div class="container">
                <h2>UNIX Web Based Terminal 1.0</h2>
                <br />
                <p><b>output</b></p>
    
                <span id="User"></span>
                <input id="cmd" type="text" class="textbox" size="20" />
    
                <div class="output">
                    <p><span id="txtOut"></span></p>
                </div>
            </div>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.