Uncategorized

javascript – Want to take input from console on website and pass it throguh to Python Script



I’m a Computing A-Level student, now I have a really nice project idea in mind, however one crucial part is taking inputs from a website and passing those inputs into my Python script to do the back-end work.

Could someone explain how I could do this with what I’ve got so far? Here is my HTML script so far:

<!DOCTYPE html>
<html>
  <head>
    <title>Chem Calculator</title>
    <style>
      img {
        width: 100px;
        border-radius: 50px;
        float: left;
        margin-right: 10px;
      }

      .username {
        font-weight: bold;
      }
    </style>
  </head>
  <body style="background-color: #5dd0f9">
    <img src="images/fritz.jpg" />
    <p class="username">Biele</p>
    <p>Computing A Level.</p>
  </body>
  <h1 style="font-size: 25px">Balancing Equations Calculator</h1>
  <body>
    <button
      onclick="doSomething()"
      style="background-color: aqua; color: goldenrod; border-radius: 5px"
    >
      David Button
    </button>
    <form action="" id="form" onsubmit="sendConsole(event)">
      <label for="Element">Element:</label>
      <input
        type="text"
        id="Element"
        name="Element"
        style="height: 50px; width: 50px"
      />
      <button type="submit">Submit</button>
    </form>
    <form id="Test2" onsubmit="sendConsole(event)">
      <label for="Test2">Element2:</label>
      <input type="text" id="Element2" style="height: 50px; width: 50px" />
      <button type="submit">Enter</button>
    </form>

    <p id="test">Hello world</p>
    <script src="buttonclick.js"></script>
  </body>
</html>

And here is the js script linked to the sendConsole function called in the first Element input for the website.

function sendConsole(event){
    event.preventDefault();
    let Element = document.getElementById("Test2");
    console.log(Element.value);

If possible, could someone please change my code to not only allow for it to take an input from the website and pass it to the python script, but also to explain how everything works and why you need a certain piece of code to achieve this, as I’m not trying to cheat or anything I would like to also learn why this works. (My teacher said I was allowed to do this lol)

Thanks 🙂



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *