This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - "Button event code" to get data from field1 and put it in filed2. when button clicked

fli - Wednesday, August 25, 2010 5:48 AM:

when i a method for a "button onClick"

what should I write to get text from 1 box to another. ?

where can I find a definition for these window.  calls ?

thanks

Christoffer



Brian - Saturday, September 4, 2010 8:08 AM:

Hi Christoffer,

I don't know if you figured this one out yet. It was nagging at me because it should be easy.

After some effort I get the following:

IN the onClick of the button:

Assuming you have two text fields called "text0" and "text1"

 

var myTxt0 = document.getElementsByName("text0");

var myTxt1 = document.getElementsByName("text1");

 var myVal01 = myTxt0[0].value;

var myVal00 = myTxt1[0].value;

myTxt1[0].value = myVal01;

myTxt0[0].value = myVal00;

 return true;

 

This swaps the values in the fields.

I'm sure there are more "correct" ways of doing this but I couldn't figure them out.

The obvious "myTxt0.getAttribute("value") is not supported by the element returned in the document.getElementByName("text0").

Anyway. If this helps you then that's great. If not it has been a useful excercise for me.

Cheers,

Brian.



Brian - Saturday, September 4, 2010 8:38 AM:

You can get a full collection of all of the "input" elements on the form using this:

var elements = document.getElementsByTagName("input");

var valArray = new Array();

var valArray2 = new Array();

var nameArray = new Array();

for (var j=0;j<elements.length;j++)

{

    var fld = elements[j];

    nameArray[j] = elements[j].name;

    valArray[j] = fld.value;

    valArray2[j] = elements[j].value;

}

Then once you have all the elements you can do things with them in a more "normal" fashion by looping though the array to find the input field you want and working with it.

Cheers,

Brian.



fli - Monday, September 6, 2010 3:42 AM:

Brian

Thanks for your answer, it works perfekly for me.

do you know if there i a way to do the same in c# or is it only possible to run c# on the server-side

Christoffer



Brian - Monday, September 6, 2010 6:03 AM:

Christoffer,

C# and VB are server side programming tools only.

Javascript is the Client side programming language.

Cheers,

Brian.