# \[SOLVED\] UserCode Input in sitemap

**URL:** <https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465>\
**Category:** Items & Sitemaps\
**Created:** [December 11, 2018, 12:50pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465 "2018-12-11T12:50:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jozef\_Szabo](https://community.openhab.org/user_avatar/community.openhab.org/jozef_szabo/32/37104_2.png) [@Jozef\_Szabo](https://community.openhab.org/u/Jozef_Szabo)\
**Post date:** [December 11, 2018, 12:50pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/1 "2018-12-11T12:50:56Z")

</div>

Hi,  
i need to input some userlevel string as “1234”. According this I will mask some sitemap rows.  
How to do it please ?

items

```csv
String usercode "4 digits user code [%.0f]"

```

sitemap seems be wrong, need input some digits via keyboard like “1234” not arrows down/up

```csv
Setpoint item=usercode

```

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 11, 2018, 1:07pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/2 "2018-12-11T13:07:47Z")

</div>

There is currently no way to enter arbitrary text via sitemap.

People have created keypad type things hough.

> [@\[SOLVED\] BasicUI - keypad](https://community.openhab.org/t/basicui-keypad/28818):
>
> Hi, I would like to arm/disarm my alarm via BasicUI. I would need to enter a 4-digit code for this. I have tried this: Switch item=Tex\_UDP\_Send label="Alarm keypad" mappings=[KEY0="0", KEY1="1", KEY2="2", KEY3="3", KEY4="4", KEY5="5", KEY6="6", KEY7="7", KEY8="8", KEY9="9", KEYN="N", KEYY="Y"] But this gets very messy. I guess “switch” was not designed for that many selection options. I also tried this: Selection item=Tex\_UDP\_Send label="Alarm keypad" mappings=[KEY0="0", KEY1="1", KEY2="2"…

---

<div class="post-metadata">

**Author:** ![Jozef\_Szabo](https://community.openhab.org/user_avatar/community.openhab.org/jozef_szabo/32/37104_2.png) [@Jozef\_Szabo](https://community.openhab.org/u/Jozef_Szabo)\
**Post date:** [December 11, 2018, 1:31pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/3 "2018-12-11T13:31:38Z")

</div>

Thanks, but it is no nice method.  
A user verification is most important, like PIN protection.

---

<div class="post-metadata">

**Author:** ![Vradatta](https://community.openhab.org/user_avatar/community.openhab.org/vradatta/32/56686_2.png) [@Vradatta](https://community.openhab.org/u/Vradatta)\
**Post date:** [December 11, 2018, 1:54pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/4 "2018-12-11T13:54:25Z")

</div>

I think HabPanel is the better UI for this.  
There is also a Custom Widget for this:

[https://community.openhab.org/t/custom-widget-keypad/18154](https://community.openhab.org/t/custom-widget-keypad/18154)

---

<div class="post-metadata">

**Author:** ![Jozef\_Szabo](https://community.openhab.org/user_avatar/community.openhab.org/jozef_szabo/32/37104_2.png) [@Jozef\_Szabo](https://community.openhab.org/u/Jozef_Szabo)\
**Post date:** [December 11, 2018, 1:59pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/5 "2018-12-11T13:59:10Z")

</div>

Thanks, but i need to protect some setpoint functions in one sitemap from unauthorised manipulation  
from all web and mobile apps. I don’t want to use many sitemaps.

HabPanel widged is nice for touch display.

It must not be a string value, numerical 4 digit value is OK, but how put it in sitemap as number not with incremental arrows ?

---

<div class="post-metadata">

**Author:** ![hmerk](https://community.openhab.org/user_avatar/community.openhab.org/hmerk/32/56432_2.png) [@hmerk](https://community.openhab.org/u/hmerk)\
**Post date:** [December 11, 2018, 2:04pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/6 "2018-12-11T14:04:00Z")

</div>

As already said, there is no such a function in BasicUI od ClassicUI and I am afraid there never will be, as nobody steped up to implement this, cause of other existing alternatives.

---

<div class="post-metadata">

**Author:** ![george.erhan](https://community.openhab.org/user_avatar/community.openhab.org/george.erhan/32/71443_2.png) [@george.erhan](https://community.openhab.org/u/george.erhan)\
**Post date:** [December 11, 2018, 3:01pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/7 "2018-12-11T15:01:46Z")

</div>

You can do it using a Webview element in sitemap and create a html file in your html folder with a java script sending the value on specific triggers, just like in this example:

> [@Input field for number/free text for openHAB UIs](https://community.openhab.org/t/input-field-for-number-free-text-for-openhab-uis/12461):
>
> Hi all, I would need (as I think many of you) a field to enter a value or free text in the UIs of openHAB, so I tried to use a webview to display a small html page containing a text field and some javascript code to manage everything. This is the html files textInput.html (in OPENHAB\_DIR\webapps\static) \<html\> \<script language="JavaScript"\> function getParam(param) { var qs = (function(a) { if (a == "") return {}; var b = {}; for (var i = 0;…

😉

---

<div class="post-metadata">

**Author:** ![Jozef\_Szabo](https://community.openhab.org/user_avatar/community.openhab.org/jozef_szabo/32/37104_2.png) [@Jozef\_Szabo](https://community.openhab.org/u/Jozef_Szabo)\
**Post date:** [December 23, 2018, 8:00pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/8 "2018-12-23T20:00:00Z")

</div>

Hi George.  
Thanks for post.  
I make some substitution in script:

```csv
<html>
<script language="JavaScript">
    function getParam(param)
    {
        var qs = (function(a) {
            if (a == "") return {};
            var b = {};
            for (var i = 0; i < a.length; ++i)
            {
                var p=a[i].split('=', 2);
                if (p.length == 1)
                    b[p[0]] = "";
                else
                    b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
            }
            return b;
        })(window.location.search.substr(1).split('&'));       
        return qs[param]
    }
    function checkInput(id)
    {
        var x=document.getElementById(id).value;
        if (isNaN(x)) 
        { document.getElementById(id).value = ""
            return false;
        }
        else
        { return true;
        }
    }
    function resetInput(id)
    {
        document.getElementById(id).value = ""
    }
    function httpGetAsync(theUrl)
    {
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.open("GET", theUrl, true); // true for asynchronous 
        xmlHttp.send(null);
    }
    function sendValue() {
        if checkInput('Userlevel') 
        {
            url = "http://192.168.100.11:8080/CMD?" + getParam('item') + "=" + document.getElementById('Userlevel').value
            httpGetAsync(url)
            resetInput('Userlevel')
        }
         else {
            resetInput('Userlevel')
        }
    }
</script>
<form>
    <input name="Userlevel" id="Userlevel" type="number" onChange="sendValue()">
</form>
</html>

```

They are:  
textInput → Number item=Userlevel  
localhost → RpiIP  
type=text → number (Userlevel is a Number Item)

But transfer to Userelevel item does not work.  
What is the problem please ?  
Thanks.

---

<div class="post-metadata">

**Author:** ![george.erhan](https://community.openhab.org/user_avatar/community.openhab.org/george.erhan/32/71443_2.png) [@george.erhan](https://community.openhab.org/u/george.erhan)\
**Post date:** [December 23, 2018, 8:13pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/9 "2018-12-23T20:13:36Z")

</div>

If you are using openHAB 2.x the above script will not work (openHAB 2.x is using the REST API). Use the one on post number 6 in the same link I’ve posted previously! It should work.

---

<div class="post-metadata">

**Author:** ![george.erhan](https://community.openhab.org/user_avatar/community.openhab.org/george.erhan/32/71443_2.png) [@george.erhan](https://community.openhab.org/u/george.erhan)\
**Post date:** [December 23, 2018, 8:26pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/11 "2018-12-23T20:26:31Z")

</div>

Yes!

---

<div class="post-metadata">

**Author:** ![Jozef\_Szabo](https://community.openhab.org/user_avatar/community.openhab.org/jozef_szabo/32/37104_2.png) [@Jozef\_Szabo](https://community.openhab.org/u/Jozef_Szabo)\
**Post date:** [December 24, 2018, 1:18pm UTC](https://community.openhab.org/t/solved-usercode-input-in-sitemap/59465/12 "2018-12-24T13:18:31Z")

</div>

Thanks George working OK inOH2.  
Is it possible to extend the code for only four digit input (PIN number) and delete the input filed after pressing Enter ?  
Can be AJAX values supressed, that the last values are not remembered ?  
Thanks.
