Is there a way to create submit buttons that trigger printing in HTML? Additionally, how can I design a text input that spans 100% width on the same line as a <span>, <p>, or <div>?

These are the files I have:

.dir {
  color: white;
  font-family: "Lucida Console", Monaco, monospace;
  font-size: 16px;
}
.cmdline {
  font-family: "Lucida Console", Monaco, monospace;
  background-color: black;
  border: 1px solid black;
  color: white;
  font-size: 16px;
  width: 100%;
}
.cmdline:focus {
  outline: none !important;
  border: 1px solid black;
}
.blink_text {
  -webkit-animation-name: blinker;
  -webkit-animation-duration: 1s;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
  -moz-animation-name: blinker;
  -moz-animation-duration: 1s;
  -moz-animation-timing-function: linear;
  -moz-animation-iteration-count: infinite;
  animation-name: blinker;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  color: white;
}
@-moz-keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
@-webkit-keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
@keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
<!DOCTYPE html>
<!--<>-->
<!--<ink rel="stylesheet" type="text/css" href="interface.css">-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!--</>-->

<body style="background-color:black;">
  <span class="dir">~/Link/Hydrogen/Helium/Lithium></span>
  <input class="cmdline" autofocus>
  <input type="submit" style="visibility: hidden;" />
</body>

Disregard the comments... How can I create a functionality where entering a command will trigger a response to be printed? Kind of like what's seen on telehack.com? Additionally, I need help figuring out how to make an input with 100% width appear in the same line as a span, p, or div. Appreciate any assistance in advance.

Answer №1

Your Second Query

In order to align the input field next to the directory, I enclosed them both within a <table>:

CSS Styles

.intable {
  width: 100%;
}

HTML Structure

<span id="output" class="dir"></span>
<form id="inform" autocomplete="off">
  <table class="intable">
    <tr>
      <td>
        <span class="dir" id="directory">~/Link/Hydrogen/Helium/Lithium></span>
      </td>
      <td style="width: 100%">
        <input class="cmdline" id="inbox" autofocus>
      </td>
    </tr>
  </table>
  <input type="submit" style="visibility: hidden;" />
</form>

(Explanation about the <form> will follow shortly)

Your Initial Inquiry

Fetching User Input

The rationale behind enclosing everything in a form was for easier retrieval of user input:

$(document).ready(function() {
  $("#inform").submit(function(e) { //Listen for user input
    e.preventDefault();             //Prevent page reload
    var input = $("#inbox").val();  //Retrieve entered text
    $("#inbox").val("");            //Assuming you want to clear this after use
    printSomething(input);          //Process and output input
  });
});

Displaying Output

I included the

<span id="output" class="dir"></span>
as a placeholder for displaying the output.

function printSomething(input)
{
  //Combine directory text with user's input for output
  var output = $("#directory").html() + input + "<br />";

  //Customize this section according to your processing needs
  if(input.length > 0)
  {
    output += "You typed: " + input;
  } else {
    output += "No input provided!"
  }
  //Add line break to move directory to new line, since span doesn't do it automatically
  output += "<br />";

  //Append the new content to the output display area
  $("#output").append(output);
}

$(document).ready(function() {
  $("#inform").submit(function(e) {
    e.preventDefault(); //Prevent page reload
    var input = $("#inbox").val(); //Retrieve entered text
    $("#inbox").val(""); //Assuming clearing is required
    printSomething(input);
  });
});

function printSomething(input) //Accuracy of function purpose...
  {
    var output = $("#directory").html() + input + "<br />";

    //Customization needed here for specific processing
    if (input.length > 0) {
      output += "You typed: " + input;
    } else {
      output += "No input provided!"
    }
    output += "<br />";

    $("#output").append(output);
  }
.dir {
  color: white;
  font-family: "Lucida Console", Monaco, monospace;
  font-size: 16px;
}
.cmdline {
  font-family: "Lucida Console", Monaco, monospace;
  background-color: black;
  border: 1px solid black;
  color: white;
  font-size: 16px;
  width: 100%;
}
.cmdline:focus {
  outline: none !important;
  border: 1px solid black;
}
.blink_text {
  -webkit-animation-name: blinker;
  -webkit-animation-duration: 1s;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
  -moz-animation-name: blinker;
  -moz-animation-duration: 1s;
  -moz-animation-timing-function: linear;
  -moz-animation-iteration-count: infinite;
  animation-name: blinker;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  color: white;
}
.intable {
  width: 100%;
}
@-moz-keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
@-webkit-keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
@keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>

<body style="background-color:black;">
  <span id="output" class="dir"></span>
  <form id="inform" autocomplete="off">
    <table class="intable">
      <tr>
        <td>
          <span class="dir" id="directory">~/Link/Hydrogen/Helium/Lithium></span>
        </td>
        <td style="width: 100%">
          <input class="cmdline" id="inbox" autofocus>
        </td>
      </tr>
    </table>
    <input type="submit" style="visibility: hidden;" />
  </form>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I substitute a specific portion of a string with values that correspond to items in an object array?

I am currently working on a task that involves extracting values from objects in a string to perform mathematical operations. While I have managed to retrieve the data and match the values enclosed in brackets, I am facing a roadblock in terms of what step ...

Obtaining and Assigning Filter Values in Material Table

Is there a way to programmatically obtain and adjust filter values with material-table? I am looking to enable users to save filter settings as reports and access them whenever necessary. ...

Using Node.js to integrate Stripe payment method

After successfully implementing a stripe payment method with node and express, I encountered some issues. Although the payment runs smoothly and returns a success message, the customer is not being added to the list of stripe customers. Additionally, my no ...

What happens to the XMLHttpRequest when the browser is closed?

If I begin an XMLHttpRequest when the onClose event of the tab or browser window is triggered, what should I anticipate? Will the request be terminated if it takes too long or will it be allowed to complete even as the window closes, possibly resulting in ...

What is the process for configuring simultaneous services on CircleCI for testing purposes?

My current project involves running tests with Jasmine and WebdriverIO, which I want to automate using CircleCI. As someone new to testing, I'm a bit unsure of the process. Here's what I've gathered so far: To run the tests, I use npm tes ...

Displaying Data in Table Using Ajax Request

I'm working on a project that involves creating an HTML table from an ajax request pulling SharePoint list items. The screenshot provided demonstrates how it functions and what it displays after the button is clicked. However, I am looking for a way t ...

Learn the process of including an active class using jQuery from an external active.js file!

This JavaScript code snippet $(function() { $("#navbar-nav li").click(function($) { // remove classes from all $("li").removeClass("active"); // add class t ...

Discover the method for converting a local file into a string

Looking to retrieve and read an SVG file in Angular 6 from the assets folder as a string. I've attempted the following: this._htmlClient.get('../../assets/images/chart1.svg').subscribe(data => { console.log('svg-file: ', ...

Converting an HTML table to a CSV file with pure JavaScript

I need to implement a CSV download feature on my website that converts the HTML table into downloadable content. While searching for a suitable plugin, I came across resources like http://www.dev-skills.com/export-html-table-to-csv-file/ which uses PHP s ...

Implementing service injection within filters in NestJS

Looking to integrate nestjs-config into the custom exception handler below: import { ExceptionFilter, Catch, ArgumentsHost, Injectable } from '@nestjs/common'; import { HttpException } from '@nestjs/common'; import { InjectConfig } fro ...

Using Rails to render partials with Ajax and buttons

I have a webpage that showcases a list of microposts along with different tabs like Most Recent, Most Discussed, and Most Viewed. I am looking for a way to dynamically render the various list orders of microposts without having to refresh the entire page u ...

My CSS disappears when using an ASP.Net MVC form

Unable to find any similar issue on Google... seeking some assistance. When I apply CSS formatting to style my form as desired, it displays correctly on the page without any issues. However... When I place the actual form within the following code snipp ...

The shadow is obscured by a block that has an 'overflow: scroll' property

One block on the left displays the list, while another shows detailed information with a shadow effect. The issue arises when the left block has 'overflow: scroll', causing elements' backgrounds to spill over the shadow. .div-left { flo ...

Dynamic JSX tag including attributes

In my project, I have a set of components stored in a folder named systemStatus. These components are accessible through an index.js file as follows: export UserCount from './UserCount' Additionally, I have a JSX component called Status which i ...

Function utilizing variables parsed by Angular directive

I am currently working on a directive that I have created: feedBackModule.directive("responseCollection", ['deviceDetector', function (deviceDetector) { return { restrict: "E", templateUrl: 'js/modules/Feedback/direc ...

Are there any AJAX tools or packages in Node.js Express for connecting (posting/getting) with other servers and retrieving data?

Can someone please guide me on how to utilize ajax in node.js to send and receive JSON data from another server? Is there a package available that allows for this functionality, similar to jQuery's $.ajax, $.post, or $.get methods? ...

What could be causing DataTable to insert a row at the beginning of my table?

Similar Question: Is the fnAddAdd() function of jquery datatable plugin used to add rows to the top or bottom of an html table? I am currently working on implementing datatables in my application and encountered an issue when dynamically adding rows. ...

establishConnection(); ^ TypeError: establishConnection is undefined

While attempting to connect to MongoDB, I encountered an error in my index.js file. require('dotenv').config(); const express = require('express') const app = express(); const cors = require('cors'); const connection = require ...

vue implementing autoscroll for long lists

I am looking to implement an autoscrolling log feature on my webpage that is dynamically fetched from a REST endpoint. To handle the potentially large size of this log, I decided to use vue-virtual-scroll-list. Additionally, I wanted the log to automatical ...

Execute JavaScript AJAX Request On Page Load

I am facing an issue with creating an onload event in which an AJAX function needs to be called and passed a value. The challenge lies in the fact that I have both my header and footer split into sections via PHP, therefore I cannot place it on the body ta ...