PDA

View Full Version : How to swap & display two text field values?


xcd2xs
2008-12-14, 01:00
I have two text fields (1st called FROM, 2nd called TO) and one button.

Enter a word in each of the text fields.

When the button is pressed I want text field 1 (FROM) to contain text field 2's (TO) value, and vice versa. The screen should show the values swapped.

Does anyone have a sample of how to do this? I'm stuck.

Partial
2008-12-14, 02:10
Sure, use javascript.

var fieldOne = document.getElementById(idOfFieldOne);
var fieldTwo = document.getElementById(idOfFieldTwo);

var tempValue = fieldOne.value;
fieldOne.value = fieldTwo.value;
fieldTwo.value = tempValue;

Something like that should work.

xcd2xs
2008-12-14, 11:56
Correct answer... unfortunately, I wasn't clear in my question - apologies ;-)

I should have included that I'm writing the method in Objective-C on the iPhone.

Thanks.

Partial
2008-12-16, 22:30
Same principal should apply, just google the syntax. I don't know objective-C. I'm sure you'll do basically the same thing.

xcd2xs
2008-12-22, 21:56
Ok, just to bring this to a close.

Being new to the iPhone SDK and Objective-C, I was missing the method to reload the view; my routine for swapping he variables was fine. However, I couldn't figure out how to refresh the display. Here's what was needed to reload the view:

[self reload];

{sigh} noob mistake, but thought I'd post out the resolution anyway.