Javascript to send command to an item

Could somebody please assist what to put instead of the placeholder XXXXX below in order to send a command to an item with javascript?
I need to do it this way - no cURL or anything else available.

I tried with “state”, “status”, “command”, “CMD”, “data”, “value” but with no luck

javascript:(
   function()
      {
      document.body.innerHTML='
         <form method="POST" action="http://192.168.178.61:8080/rest/items/Test_item/" enctype="text/plain">
         <input name="XXXXX" value="ON">
         </form>';
      document.forms[0].submit()
      })();

Have you tryed without a name?

You could try fetch()

var myHeaders = new Headers();
myHeaders.append("Content-Type", "text/plain");

var raw = "ON";

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("http://192.168.178.61:8080/rest/items/Test_item", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

In this case the syntax is probably wrong as the script is not executed.

Background for this is, I need a one-liner to be executed from an IoT device which does not have an http post command option.

I tried your suggestion like the following but it does not work either

javascript:(
   function()
      {
      fetch("http://192.168.178.61:8080/rest/items/Dunkelheit",
         {method:'POST',
         headers:{'Content-Type':'text/plain'},
         body:'ON'})
      })();

Can you share what the IoT device is?

That is to me a generic solution if a device is not able to execute an http post command like a camera, etc.
Currently I am using the following:

http://IP:8080/basicui/CMD?Item=ON 

but that will be probably obsolete in OH3.

A few hints are mentioned in this thread https://community.openhab.org/t/how-to-post-command-to-item-using-html-form/

Thanks Wolfgang,
that helped as I understand now that I have to pursue denominator’s suggestion (using fetch instead of submit).
However, the idea from post #1 can be executed e.g. from a browser whereas I do not see a way to start the fetch command from a browser. Any idea on this?

Use Google to search javascript fetch ? This is not a search engine replacement not a site to train how to use the Internet.

No, you didn’t get me. I am not asking how to execute this script nor am I asking how to write it.
I am asking how to put this into an “one-liner” so that I can execute it e.g. from a browser.

Put this into your browser and you will se what I mean:

javascript:(function f(){fetch("http://192.168.178.61:8080/rest/items/Dunkelheit",{method:'POST',headers:{'Content-Type':'text/plain'},body:'ON'});f()})();

Got it.
When you enter this into your browser you can send a command to an item via REST API (http post method):

javascript:(function f(){return fetch("http://192.168.178.61:8080/rest/items/Name-of_item",{method:'POST',headers:{'Content-Type':'text/plain'},body:'ON'})})();

Thanks denominator and Wolfgang