Do you have an existing script, or are you working from scratch? It's usually easier (at least at first) to adapt existing scripts. Try searching on userscripts.org for a lot of good examples.

On 2010-02-08 19:05, Haias wrote:
I want to try and get this greasemonkey program to be able to change
the value of a textbox every time it opens a page. Some questions:

Would I need to use the name of the textbox or the id?

You can do it either way, but usually the id attribute is best, if available. (In point of fact, it's possible to use random things like the width of the textbox, the specific elements that contain it in the DOM tree, and so forth to narrow it down.)

Would I have to reference all the<div>  tags before it?

I'm not quite sure what you mean, but I really don't think so.

What syntax would I use?

I suppose the third question is the most important... well, I would be
really grateful if someone took the time to help me out. ;)

Here's an example script that I recently wrote for a semi-private project; I've added comments to explain the pieces.

// ==UserScript==
// @name            File as UNCO
// @namespace       com.tuggy.nathan
// @description     File all new bugs as UNCONFIRMED by default (useful only if 
you have CANCONFIRM)
// @include         https://bugzilla.mozilla.org/enter_bug.cgi*
//
// @copyright       2010, cc (<http://carlclark.mp/>)
// @license         GPL version 3 or any later version: 
http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

/* The bit in double-quotes there is the id attribute; change it appropriately 
*/
var /* I suggest you rename this variable ==>*/elemStatus = 
document.getElementById("bug_status"), i;
if (elemStatus) {
  /* A for loop that you won't need */
  for (i = 0; i<  elemStatus.options.length; i++) {
    if ("UNCONFIRMED" === elemStatus.options[i].text) {
      elemStatus.selectedIndex = i;
    }
  }
  /* end of the for loop, which you can cut out */
}


What you'll want to do is replace the for loop in there with a statement to assign the variable's textContent property whatever value you want, for example:

  elemStatus.textContent = "something useful";


P.S. Normally I (and the others on this list) don't go into this level of detail on basic scripts; we expect most people to have a good enough understanding of web development already that Javascript is pretty familiar to them. So read up on http://www.w3schools.com/js/ and http://www.w3schools.com/htmldom/ -- those should get you started.

--
cc | pseudonymous |<http://carlclark.mp/>


--
|| Insert clever saying here... || http://tagzilla.mozdev.org v0.066

--
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to