How store user input from HTML/Javascript to variable

This forum is for conversations about Internet development using CXP, WebSockets, HttpEndPoint, etc.
Post Reply
Message
Author
Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

How store user input from HTML/Javascript to variable

#1 Post by Victorio »

Hi,
I do not know many things ;) but now I need know, how store user input, for example from form to variable and use it in other place in Xbase++ source.
I am using example from xb2net, and if run Login.htm, there write user name,and password, this I know how use later.

But when I include script in htm, how is syntax to store it to variabe which program can view ?

example

Code: Select all

<script type="text/javascript">
    function myFunction(x) {
	px=x.rowIndex-1;
	px2="000000";
	alert("Klikol si na riadok : "+
		px+", CISKU="+px2);
      }
</script>
I need store it to local or public variable, when user select row from table.

Or better say, I need create table browser, and when user select row from it, store selected row data to variable and use it in other process.

Note : I want create webserve, running on some computer and users access from internet browser., so this look very difficult to create some working app... :o

I have headache from studying HTML, Javascript and including it to Xbase++ application.

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: How store user input from HTML/Javascript to variable

#2 Post by c-tec »

Hello,
make a form on this page and a hidden formvar, here you can store all your calculated values etc. In XB2NET you can then extract the form values very easy.
regards
Rudolf
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: How store user input from HTML/Javascript to variable

#3 Post by Victorio »

Rudolf, can you look for my source and screens ?

Now this works :

browse table

if moving over rows, this change color,

when click radio and click down button Výber/(Select) this show alert window with value of selected row.
at this moment I want store selected data to variable (local, public) which can use at other place in program

but this is not very good, because I store value of dbf fields when table rows is creating

Code: Select all

pomcisku:=alltrim(str(CISKU))
	pomnazov:=alltrim(NAZOV)
after it store to "radio" when html rows created :

Code: Select all

cHtml += "<td><input type='radio' name='rctrl' value= "+pomcisku+"-"+pomnazov+"></td>"
this works only if click to radio button! , not work for entire row

and then use button at bottom of table :

Code: Select all

	    "<p>" +;
	    "    <button onclick="+"alert(radioValue(document.getElementsByName('rctrl')))"+">" +;
	    "      Vybrané kat.územie ?" +;
	    "    </button>" +;
	    "</p>"
this show alert window with values

A have scripts but do not know how "tell" script to store values to variable that can use in next processes.
Also I need script that store entire row values to array
And I want to select row when click at any place row, not only to button.

For me will be very useful some little example with browser table with selecting row by doubleclick or also select and mark (change color of entire row) row and then select with button .


Thanks for any advice.
Victorio

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: How store user input from HTML/Javascript to variable

#4 Post by c-tec »

Hello,
put all in a form:

Code: Select all

  <form action="callfunction" method="POST" name="callfunction" id="callfunction">
    <input name="myvar"   type="hidden" value="?">
...
setting value in js:

Code: Select all

 document.callfunction.myvar.value=myclickvalue;
regards
Rudolf
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: How store user input from HTML/Javascript to variable

#5 Post by Victorio »

Rudolf, thanks for recommendation, but I totally losing in it. I do not know how use it. :roll:
I do not know, how "tell" some form/html formular, or browser , where are some table data , and after select some row , when ending this form, to store value from selected row to variable, which can use outer html code,.
For example select row with some perston from browser and store his data to variables or array and then working with them.

I am losing in syntax like document.callfunction. ... this, and also javascript, html and other are new for me.
(a am Clipper programmer and with XBase working only from 2015)

Can You ,or any good people show some little example how do it ?
For example I have HTML code with table rows and table data,
when select row, i click to some button, and after it HTML formular close and program continue with data from stored data selected row.

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: How store user input from HTML/Javascript to variable

#6 Post by c-tec »

Hello Victorio,
I would need a sample HTML with the table for this. I use datatables, very powerful. When selecting a row, for editing I can popup with Javascript a separate window or change to a new site and return to
the table. Attached a sample. But you should start with standard tables. I use also METRO UI
regards
Rudolf
Attachments
2017-09-19_08h34_28.png
2017-09-19_08h34_28.png (34.23 KiB) Viewed 33784 times
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: How store user input from HTML/Javascript to variable

#7 Post by Victorio »

Hi Rudolf,
Thanks for answer. Yes, nice design, I also want create some like this : https://kataster.skgeodesy.sk/

If you can look for my source, I am sure, you found many strange functions, but at this moment I tryed differrent things to learh how it works.

In attach is sample source from xb2net example with some modifications and also my DBF table RKU807.DBF to examine it.
1. I run webserve (for example like this :
WEBSERVE /IP:192.168.0.234 /PORT:1234 /SPORT:1234 /CPU:1
2. in index.htm calling Login_raukn.htm as here
<tr>
<td><img SRC=Bullet.gif ALT="*"></td>
<td class="link"><a href=/TC/Login_Raukn.htm class="cold" title="Run Web Raukn">Web Raukn Application Test</a></td>
</tr>
3. In login_raukn.htm (in TC subdir) for testing is UID "24342" , without password
4. then call function with action='Login_Raukn' , this is in Timeclock_raukn called as WEBPROC Login_Raukn() PATH TC
5. after test UID go oClient:HTTPResponse:Content := DrawOuterFrame_Raukn( oClient:GetSessionHandle() )
6. when open Timeclock window , I select from menu in WEBPROC TimeClock_Raukn() PATH TC
case cAction == "VYBER KATASTRALNE UZEMIE"
and start WEB_TC_BrowseTable( xbBase64Encode(var2char(aParam)) )
7. Browsetable is also modified to open my database (Foxpro indexed ) RKU807.DBF, because there is dbesys modified and also some LAT_IBM function to convert umlauts
8. When show window with table, I select row (with radio button or click to row), and when LOGOUT, or click button
Logout_raukn_ku i need to save variable RCTRL to some Local or Public variable to select this record

I do not know why UID I can access, but same way with RCTRL (used also in javascript functions) still NIL value.
There are many various examples, which I tryed.

I know, this need some time to look for this, If you can, and have some little time to look, this help me.

For example in function
WEBPROC Logout_Raukn() PATH TC

is GETVAR UID AS nID
but in nID is NIL,

and when use this :

Local pomUID:=oClient:GetCargo("UID")
i know who is logged in also when close login window.

But when use this :
cCISKU:=oClient:Getvar("RCTRL")
I do not know value RCTRL,
I mean, my wrong source row document..... I do not know how use it

Thanks
Viktor
Attachments
#Rudolf.zip
(47.32 KiB) Downloaded 1666 times

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: How store user input from HTML/Javascript to variable

#8 Post by c-tec »

Hello Victor,
there are some files missing, can you please add them to the zip
And include your point 8 HTML output for checking, this is easier for me.
I have a function for my framwork where I retrieve vars you can get in various ways, maybe you can implement this part from it for your project. With oSV := get_clientvar() at the begin of your web_*() function you have all you need. When you dont find it in oSV:aForm you have a problem in your HTML code. You see here also that you must keep track of the SSID.
Also a little script to fill the hidden vars in the form and if needed the name of the action.


regards
Rudolf

Code: Select all

function get_clientvar(lLogin)
******************************************************************
local aRet := {},cSID := "",oClient := ThreadObject(),lRegister := .f.
Local cAction    := oClient:HTTPRequest:Path()
local cCommand   := oClient:HTTPRequest:command
local cStartLine := xbunescape(oClient:HTTPRequest:startline)
local oContent   := oClient:HTTPRequest:content   // xbForm
local cQuery     := oClient:HTTPRequest:eQuery
local x,aForm := {},cTmp,lError := .f.,cJson := "",aTmp
local cType := oClient:HTTPRequest:contenttype,cFTyp := ""
LOCAL oSV,cHandle := ThreadObject():GetSessionHandle()
default lLogin to .f.

if empty(cHandle) .or. valtype(cHandle) # "C"
     cHandle := ""
endif

DCVARGROUP oSV NAME "SessionVar" cSH := "?",cSID := "", lAdmin := .t., nUserID := 0,cUserName := "",cPWD := "",cControl := "",cEmail := "", cAction := "",;
      cCommand  := "", cStartLine := "", oContent  := NIL,aForm := {},cFunction := "",cLogin := "",cOptions := "",nRec := 0,aVars := oClient:HTTPRequest:varlist,aStruct := {},cTemplate := "",cUserRole := "",aFormDef := {}

if "CALLDEBUG" $ oWF:cDebugMode
     altd()
endif
if valtype(oContent) = "O" .and. oContent:classname() = "xbForm"
     aForm := oContent:varlist

     if valtype(aForm) # "A"
          aForm := {}
     endif
     for x := 1 to len(aForm)
          cFTyp := "F"
          if upper(aForm[x,1]) == "_FUNCTION"
               oSV:cFunction := aForm[x,2] // direct link call
               cFTyp := "P"
          elseif upper(aForm[x,1]) = "_SID"
               cSID := aForm[x,2]
               oSV:cSID := cSID
               cFTyp := "P"
          else
               if lLogin
                    if aForm[x,1] = "UID"
                         oClient:SetCargo("LOGIN",aForm[x,2])
                         oSV:cLogin := aForm[x,2]
                         cFTyp := "P"
                    endif
                    if aForm[x,1] = "PWD"
                         oClient:SetCargo("PWD",aForm[x,2])
                         oSV:cPWD := aForm[x,2]
                         cFTyp := "P"
                    endif
                    if aForm[x,1] = "REGISTER"
                         lRegister := !empty(aForm[x,2])
                    endif
               endif
               aadd(aForm[x],cFTyp)
               aadd(oSV:aForm,{aForm[x,1],aForm[x,2],aForm[x,3]})
          endif
     next x
endif
*------------------------------------------------------------
if !empty(cType) .and. "application/json" $ cType
     cTmp := json_pretty_out(oContent)
     aJson:= jsontoarray(cTmp)
     for x := 1 to len(aJson)
          if upper(aJson[x,1]) == "_FUNCTION"
               oSV:cFunction := oSV:aForm[len(oSV:aForm)][2]
          elseif upper(aJson[x,1]) == "_SID"
               oSV:cSID := cSID
          else
               aadd(oSV:aForm,aclone(aJson[x]))
               aadd(oSV:aForm[len(oSV:aForm)],"J")
          endif
     next x
endif
*------------------------------------------------------------
if !empty(oSV:aVars) .and. valtype(oSV:aVars) = "A"
     for x := 1 to len(oSV:aVars)
          if upper(oSV:aVars[x,1]) = "_SID"
               oSV:cSID := oSV:aVars[x,2]
          elseif upper(oSV:aVars[x,1]) = "_FUNCTION"
               oSV:cFunction := oSV:aVars[x,2]
          else
               aadd(oSV:aForm,aclone(oSV:aVars[x]))
               aadd(oSV:aForm[len(oSV:aForm)],"V")
          endif
     next x
endif
*------------------------------------------------------------
if !empty(cQuery) // xmlhttp request
     cQuery := xbUnescape(cQuery)
     for x := 1 to numtoken(cQuery,"&")
          cTmp := token(cQuery,"&",x)
          if "=" $ cTmp
               aadd(oSV:aForm,{token(cTmp,"=",1),token(cTmp,"=",2),"Q"})
               if token(cTmp,"=",1) = "_FUNCTION" .and. !empty(token(cTmp,"=",2))
                    oSV:cFunction := token(cTmp,"=",2)
                    oSV:aForm[len(oSV:aForm),3] := "P"
               endif
               if token(cTmp,"=",1) = "_SID" .and. !empty(token(cTmp,"=",2))
                    cSID := token(cTmp,"=",2)
                    cSID := charrem('"',cSID)
                    oSV:cSID := cSID
                    oSV:aForm[len(oSV:aForm),3] := "P"
               endif
          endif
     next x
endif
*------------------------------------------------------------
//oClient:OpenSession()


*dcqdebug ThreadObject():GetSessionHandle()
*dcqdebug cSID
*dc_inspectobject(ThreadObject())


set_ml("akt. session:" + cHandle + " from session:" + cSID)
set_ml(cCommand + " " + oSV:cFunction + " " + cAction + " " + cQuery + " " + ntrim(len(oSV:aForm)) + " form vars")
if lLogin .and. lRegister
     oSV:cFunction := "REGISTER"
endif
if !empty(oClient:GetCargo())
     if oClient:GetCargo("SID") # NIL .and. valtype(oClient:GetCargo("SID")) = "C"
          oSV:cSH       := cHandle
          oSV:cLogin    := oClient:GetCargo("LOGIN")
          oSV:lAdmin    := oClient:GetCargo("ADMIN")
          oSV:nUserID   := oClient:GetCargo("USERID")
          oSV:cUserName := oClient:GetCargo("USERNAME")
          oSV:cPWD      := oClient:GetCargo("PWD")
          oSV:cControl  := oClient:GetCargo("CONTROL")
          oSV:cEmail    := oClient:GetCargo("EMAIL")
          oSV:cOptions  := oClient:GetCargo("OPTIONS")
          oSV:nRec      := oClient:GetCargo("RECORD")
          oSV:cTemplate := oClient:GetCargo("TEMPLATE")
          oSV:cUserRole := oClient:GetCargo("ROLE")
          oSV:aFormDef   := oClient:GetCargo("FORMDEF")
     endif
endif
if oWF:lDebug
     //dc_inspectobject(threadobject())
     set_ml("Startline:" + oClient:HTTPRequest:StartLine)
     set_ml("Path:" + oClient:HTTPRequest:path)
     set_ml("eQuery:" + cQuery)
     set_ml("content:" + var2char(oClient:HTTPRequest:content))
     set_ml("function:" + oSV:cFunction)
     if "FORM" $ oWF:cDebugMode
          for x := 1 to len(oSV:aForm)
                set_ml(oSV:aForm[x,1] + ":" + var2char(oSV:aForm[x,2]) + " [" +  oSV:aForm[x,3] + "]")
          next x
     endif
     if "CALLDEBUG" $ oWF:cDebugMode
          altd()
     endif
endif
if !"DEFCACHE" $ oWF:cDebugMode
     init_def()
endif
oLastSV := oSV
return oSV


function put_clientvar(oSV)
******************************************************************
local oClient := ThreadObject()
oClient:SetCargo("SID",       oSV:cSID     )
oClient:SetCargo("ADMIN",     oSV:lAdmin    )
oClient:SetCargo("USERID",    oSV:nUserID   )
oClient:SetCargo("USERNAME",  oSV:cUserName )
oClient:SetCargo("PWD",       oSV:cPWD      )
oClient:SetCargo("CONTROL",   oSV:cControl  )
oClient:SetCargo("EMAIL",     oSV:cEmail    )
oClient:SetCargo("CSH",       oSV:cSH       )
oClient:SetCargo("LOGIN",     oSV:cLogin       )
oClient:SetCargo("OPTIONS",   oSV:cOptions   )
oClient:SetCargo("RECORD",    oSV:nRec   )
oClient:SetCargo("TEMPLATE",  oSV:cTemplate   )
oClient:SetCargo("ROLE",      oSV:cUserRole)
oClient:SetCargo("FORMDEF",    oSV:aFormDef)
return .t.

Code: Select all

function sendform(c,cparam,cparam2,cparam3)
{

    document.callfunction._FUNCTION.value=c;
    document.callfunction.action='callfunction';
    
    if (cparam !== undefined)
    {
                document.callfunction._PARAM1.value=cparam;
        }
          if (cparam2 !== undefined)
    {
                document.callfunction._PARAM2.value=cparam2;
        }
          if (cparam3 !== undefined)
    {
                document.callfunction._PARAM3.value=cparam3;
        }
        
        
        document.callfunction.submit();
        return false;
}

Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: How store user input from HTML/Javascript to variable

#9 Post by Victorio »

Hi Rudolf,
Thanks for answer, complet files (without xb2key number) attached.

When modify batch file #spustenieservera.bat to your Ip adress, starts webserve.
Also y need change port, my set to 8101.
And then run page in order as in pictures.

I need know values from selected row when close browser with button Logout_Raukn_ku (bottom on page) or Odhlasenie in top of page. With top button ODhlasenie I tryed determine UID, as you can look, this show me, but similar RCTRL not work.

Note : For first test I store to RCTRL variable values from DBF when HTML table create, this is not good , but at this moment I do not know better way.

I will look for your attached source to understand how it works . Thank you very much.
Attachments
screens.zip
(1.08 MiB) Downloaded 1603 times
XB2NET_TEST.ZIP
(1.09 MiB) Downloaded 1714 times

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: How store user input from HTML/Javascript to variable

#10 Post by Victorio »

Hi, Rudolf,

You are true, I found some errors in my HTML, some functions not work correctly and after repair works , for example update input fields with data from selecterd rows.
I "found" this errors when open debug screen in chrome, this show me errors in some lines.

Now I trying modify source to get values from table to other use in program...

Post Reply