Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I write text in textfield

2 views
Skip to first unread message

shanya...@yahoo.com

unread,
Nov 22, 2006, 8:34:56 PM11/22/06
to
Hi:

I have been struggling this basic simple functionality for days and
appreciate if you can give me some answer/pointers.

My objective is to insert certain text string in a textfield
area(similar as pop-up menu does 'Paste' - but not by 'Copy'), so I
created a menuitem in popup and did oncommand=document.write()
( or document.writeln() ) but this does not work. How do I do this?

Thanks a bunch!
-Shanya

mark bokil

unread,
Nov 22, 2006, 9:08:32 PM11/22/06
to dev-ext...@lists.mozilla.org
<textbox id="myTB"/>

document.getElementById("myTB").value = "hello"

shanya...@yahoo.com

unread,
Nov 22, 2006, 9:41:18 PM11/22/06
to
Hi Mark:
Thanks for the quick reply and this definitely is start. However in
you solution, you have to know the ID I do not know the ID.
Perhaps I did not explain it clearly. What I want do is this. In any
textfield of the any web page, when I right click I would have a popup
menuitem call it 'Insert String', so when you select submenu such as
'Insert Hello', it will write 'Hello' string.(e.g. textfield of serach
widget). In your example you are creating textbox and then inserting
string.

Thanks again.
Shanya

mark bokil

unread,
Nov 22, 2006, 11:31:28 PM11/22/06
to dev-ext...@lists.mozilla.org
shanya...@yahoo.com wrote:
> Hi Mark:
> Thanks for the quick reply and this definitely is start. However in
> you solution, you have to know the ID I do not know the ID.
> Perhaps I did not explain it clearly. What I want do is this. In any
> textfield of the any web page, when I right click I would have a popup
> menuitem call it 'Insert String', so when you select submenu such as
> 'Insert Hello', it will write 'Hello' string.(e.g. textfield of serach
> widget). In your example you are creating textbox and then inserting
> string.
>
> Thanks again.
> Shanya
Create an extension with an overlay that adds a popupmenu with the
menuitems you want. On the window.onload event create an array of the
textfields. On an html page the element would be an input tag with an
attribute of type="text". For each textfield in your array add a
context="myPopupID" to the input element. Now when the user right-clicks
on a textfield your popupmenu from your overlay will appear. You could
get the parent of the popupmenu which would be the textfield and then
fill the textfield with the value of the menuitem selected.

Soyapi Mumba

unread,
Nov 23, 2006, 1:28:56 AM11/23/06
to shanya...@yahoo.com, dev-ext...@lists.mozilla.org
shanya...@yahoo.com wrote:

> Perhaps I did not explain it clearly. What I want do is this. In any
> textfield of the any web page, when I right click I would have a popup
> menuitem call it 'Insert String', so when you select submenu such as
> 'Insert Hello', it will write 'Hello' string.(e.g. textfield of serach
> widget).

Shanya,

You can easily do this by using Firefox's gContextMenu object as follows:

gContextMenu.target.value = "Hello";

- Soyapi
--
Soyapi Mumba
soyapi.blogspot.com
searchwith.mozdev.org

shanya...@yahoo.com

unread,
Nov 23, 2006, 11:59:42 AM11/23/06
to
Hi Mark,

I appreciate your help in this matter. Per your guidance, I created
test.xlu as you mentioned in your last reply, however there is still
something I am missing and it is not working. Please help.

Thanks,
-Shanya

------------------------------------------- test.xlu
------------------------
<?xml version="1.0"?>
<overlay id="sample"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"
src="chrome://test/content/test.js"/>

<statusbar id="status-bar">
<statusbarpanel id="my-panel" label="Welcome, Mayank Thakore!"/>
<button id="find-button" label="Find" tooltiptext="Click here to do
NOTHING!!"/>
</statusbar>

<popup id="contentAreaContextMenu">
<menuseparator id="insertstr-context-separator"/>
<menu label="Insert String" id="insertstr-context">
<menupopup onpopupshowing="displayIfDetectTextarea(this)">

<menuitem label="3Ws" id="insertstr-3ws-context"
oncommand="alert('Button was pressed!');"/>
<menuitem label="CF2C" id="insertstr-cf2c-context"
oncommand="str_parse1(this, 'Comment To Collaborator')"/>
<menuitem label="Last Note" id="insertstr-lastnote-context"
oncommand="str_parse('LastNotes')"/>
<menuitem label="Somethig else" id="insertstr-se-context"
oncommand="str_parse('SomethingElse')"/>
</menupopup>
</menu>
</popup>

<script>
function str_parse1(idName, str) {
document.getElementById( idName.id )..value = str;
}
</script>

</overlay>
---------------------------------
Thanks
Shanya

shanya...@yahoo.com

unread,
Nov 23, 2006, 12:02:45 PM11/23/06
to
Hi Soyapi:

Thanks. This works at some extent, however it replaces string not
inserts. Means it wipes out the existing text and replaces with the
string and that is not what I want. I need to just insert, such as
signature at the end.

Thanks,
Sanaya

Einar Egilsson

unread,
Nov 23, 2006, 12:39:46 PM11/23/06
to

gContextMenu.target.value += "Hello";

shanya...@yahoo.com

unread,
Nov 24, 2006, 3:39:00 PM11/24/06
to
Einar:

Thanks, that worked! Hope this function will not be deprecated or
changed :)

Shanya

0 new messages