Question
Vikram Annadurai · Aug 10, 2019

How do I get the value of text input field using JavaScript

Hey Guys,

I got stuck with this for 2 days, please help me

Actually my logic is when I enter the input on the text field in browser, the entered input to be print on the next page but I am getting "Undefined". How to i do it.

Below is my code:

 

 

Class Patient.Testing Extends %ZEN.Component.page
{

/// Class name of application this page belongs to.
Parameter APPLICATION;

/// Displayed name of this page.
Parameter PAGENAME = "userLogin";

/// Domain used for localization.
Parameter DOMAIN;

/// This Style block contains page-specific CSS style definitions.
XData Style
{
<style type="text/css">
/* style for title bar */
#title {
background#C5D6D6;
colorblack;
font-familyVerdana;
font-size1.5em;
font-weightbold;
padding5px;
border-bottom1px solid black;
text-aligncenter;
}
#login{
text-aligncenter;
font-familyAriel;
font-size3.5em;
padding180px;
font-colorbrown;
}
#content{
text-alignleft;
font-size1.5em;
font-colordefault;
font-familydefault;
}
#content1{
text-alignleft;
font-size1.5em;
font-colordefault;
font-familydefault;
}
#button{
text-alignleft;
font-size1.5em;
font-colordefault;
font-familydefault;
}
</style>
}
/// This XML block defines the contents of this page.
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen]
{
<page xmlns="http://www.intersystems.com/zentitle="">
<html id="title">Welcome!!!</html>
<vgroup width="100%">
<html id="login">Login</html>
<html id="content">Patient Id:</html>
<text id="patientId" value=""/>
<html id="content1">Password:</html>
<text id="patientPass" value=""/>
<button id="button" caption="Login" onclick="zenPage.MyMethod();"/>
</vgroup>
</page>
}
ClientMethod MyMethod() [ Language = javascript ]
{
var pId=document.getElementById("patientId").value;
var pPass=document.getElementById("patientPass").value;
document.write(pId,pPass);
}
}
 

 

Thanks

Vikram

00
2 0 4 178

Replies

Thanks Robert,

I missed this doc. Now I got some idea.

Thanks you so much....smiley

You can open your page in Chrome and then using developers Tool, you can see that ZEN page randomly assigns the ID to Components.

So best way to use zen(<ComponentID>).getValue() or setValue() for getting and setting the value.

Thanks Sourabh,

Its a wonderful idea. This make me a different way of thinking.

Thanks a lot....laugh