Text Field Values

I am new to Servoy and trying to build a sample hello world form (main) that has a text field (txtGreet) that you enter a persons name in. Upon clicking a button (btnShow) I just want the value of another text field (txtResult) to display “Hello name” where name is what was entered in the txtGreet field. I have searched the boards but cannot find how to get the value of the first field nor how to set the value of another field. I’m trying something like the following onAction event for btnShow:

function showGreeting(event) {
forms.main.elements.txtGreet.selectAll();
x=forms.main.elements.txtGreet.getSelectedText();
forms.main.elements.txtResult.value=x;
}

That is obviously not working as ‘value’ is not valid. Also, I’m not sure I should have to actually select the text from txtGreet before getting the text into a variable. Can someone please guide me in the right direction?

Thanks,

Keith

Welcome to Servoy! :)

The fields on your form should have a dataprovider. This can either be a column from a database table or a (global) variable. If your field is selected in the designer, look in the Properties view to see/change the dataprovider.
If your dataproviders are called txtGreet and txtResult, then the method will look like this:

function showGreeting(event) {
	txtResult = "Hello " + txtGreet;
}

I have no dataprovider for this simple form. So, I followed what you said and created a Global variable for each of the text fields with default values of null. When I view the form in the client I get an error that says:

Reference Error: “txtGreet” is not defined.

Like I said, I’m new to Servoy so maybe I’m missing a larger concept here, but I’m not understanding why I can’t just grab the value in a text field and use it in my code. For instance, in regular JavaScript I would simply do the following:

document.getElementByID(‘txtResult’).value = 'Hello ’ + document.getElementByID(‘txtGreet’).value;

I appreciate all the help you can give me and for you putting up with my n00b questions like this.

Here is the code for main.js for refence:
/**

  • Perform the element default action.
  • @param {JSEvent} event the event that triggered the action
  • @properties={typeid:24,uuid:“9DB56AF9-DFC3-4A2B-B983-5BCCB75231B2”}
    */
    function showGreeting(event) {
    txtResult = "Hello " + txtGreet;
    }

If you use global variables, they should be prefixed with “globals.” in your method, so:

function showGreeting(event) {
   globals.txtResult = "Hello " + globals.txtGreet;
}

I think it would help you a lot if you watched a couple of tutorials, you can find them on http://www.servoy.com/tutorials or http://www.servoyuniversity.com/