Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Halloween

macrumors newbie
Original poster
Jul 14, 2008
13
0
Hey guys, what's up? First post here (although i've been visiting MacRumors for the past years).

I've recently downloaded XCode and begun messing around with it a couple of days ago, but I'm afraid I've been having some problems with even a simple "change the text label" funcionality (if we could call it that lol).
More specifically, I want to try out a very basic operation of "Click this button to change that label's text to XYZ". Now, the tutorials at developer.apple.com haven't been particularly helpful. In fact, I am quite surprised to see that such a trivial thing does not have a tutorial for it or something like it.

Most documentation I've seen are usually either too simplified (e.g.: no code required) or not intuitive at all (damn, I miss PHP already lol), so I'd like to hear what you have to say.

Anyway, to the code - this is in the main js file, called iTSLS.js in this case.

I have a button (id: button) - which has an event handler which trigger the "mudar_texto" (translating: change text) function.
The code is:

Code:
function mudar_texto(event)
{
   if (window.widget)
   {
	// Values you provide
	var textFieldToChange = document.getElementById("showStats");	// replace with ID of text field
	var newTextFieldText = "FFS";						// value to change range to

	// Text field code
	textFieldToChange.value = newTextFieldText;
   }
}

Now, the text label which I want to change has the correct ID ("showStats") and, as you can see, the code was even copied and pasted directly from the code snippet library. I'm just wondering why on earth won't this work.

Thanks in advance guys,
Hal
 

listylister

macrumors newbie
Mar 29, 2008
17
0
Have you checked to see if the If Statement is getting executed?

I have had this problem many times. Where the If Statement is False and the code inside of it does not get parsed - Just a Suggestion.
 

Halloween

macrumors newbie
Original poster
Jul 14, 2008
13
0
Have you checked to see if the If Statement is getting executed?

I have had this problem many times. Where the If Statement is False and the code inside of it does not get parsed - Just a Suggestion.

Yes, it is. The "if (window.widget)" - if I understood it correctly from the docs - will execute something only if the widget is running on Dashboard. Either way, I have tested it both with and without it; it's not that, but thanks for the suggestion.
 

listylister

macrumors newbie
Mar 29, 2008
17
0
Could you post the other bit of code that shows the ID of the text field. And remember to wrap it in CODE tags
 

Halloween

macrumors newbie
Original poster
Jul 14, 2008
13
0
Could you post the other bit of code that shows the ID of the text field. And remember to wrap it in CODE tags

Hmmm... where?
Here's a printscreen of that ID:
 

Attachments

  • Picture 3.png
    Picture 3.png
    174.2 KB · Views: 332

listylister

macrumors newbie
Mar 29, 2008
17
0
Your id's do not match up...

The one on your attached image shows that the ID is 'showText' whilst the one in your code shows 'showStats'. You will need to match these up so that it can actually pinpoint which control you are referring to.
 

Halloween

macrumors newbie
Original poster
Jul 14, 2008
13
0
Your id's do not match up...

The one on your attached image shows that the ID is 'showText' whilst the one in your code shows 'showStats'. You will need to match these up so that it can actually pinpoint which control you are referring to.

My bad, sorry.
I tried to delete and create a new text label today, so I messed up the name; either way, I had the code updated to showText as well - just forgot to bring you up to speed on this.

Still, i doublechecked and swapped everything to 'showStats'...
Anyway, still not working :/
 

Attachments

  • Picture 1.png
    Picture 1.png
    178.5 KB · Views: 193

listylister

macrumors newbie
Mar 29, 2008
17
0
Ok i just tried setting the value of a label myself and it also failed.

Have you tried something like setValue or experimenting with different functions. I am no expert on this so what I would do is just play around with different techniques.

If someone else has anything to add please feel free :)
 

Halloween

macrumors newbie
Original poster
Jul 14, 2008
13
0
Ok i just tried setting the value of a label myself and it also failed.

Have you tried something like setValue or experimenting with different functions. I am no expert on this so what I would do is just play around with different techniques.

If someone else has anything to add please feel free :)

Ok, I just tried using:

Code:
      var a = widget.getElementById("showStats").value;
      var newTextFieldText = "FFS";
      
      a.value = newTextFieldText;

but it's still not working :confused: it just errors with "Value undefined (result of expression widget.getElementById) is not object"

If anyone manage to get some wizardry working, please let me know.

PS: Is there a way to keep the damn error log always on top of that Stack Frame view? Really bothers me that it can't be done (apparently)
PS2: And dashcode should allow us to copy/paste the error messages as well....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.