setting form parameter with same name as submit buttons

S

Steven Bethard

I have a form with three submit buttons, each of which posts a
different value for my "label" parameter. I'm trying to add keyboard
shortcuts so that you can also perform each type of submit using a
single key stroke. However, I'm finding that when I set the "label"
value and then call "submit()", I'm not seeing anything passed to my
CGI script.

I discovered that if I remove the "name" attributes from the submit
buttons and add a hidden input with the name "label", my Javascript
submit() code then works properly. But then the submit buttons no
longer work because they no longer have the necessary "name"
attribute.

What's the right way to go about this?

Here's the code I have currently:

<script type="text/javascript">
function add_label(event)
{
if (!event)
var event = window.event;
if (event.keyCode)
code = event.keyCode;
else if (event.which)
code = event.which;
var character = String.fromCharCode(code);
if (character == "B") {
document.label_form.label.value = "BEFORE";
document.label_form.submit();
}
if (character == "O") {
document.label_form.label.value = "OVERLAP";
document.label_form.submit();
}
if (character == "A") {
document.label_form.label.value = "AFTER";
document.label_form.submit();
}
}
document.onkeyup=add_label;
</script>
....
<form action="label/" name="label_form" method="post">
<input type="submit" name="label" value="BEFORE" />
<input type="submit" name="label" value="OVERLAP" />
<input type="submit" name="label" value="AFTER" />
</form>
 
S

Steven Bethard

different value for my "label" parameter. I'm trying to add keyboard
shortcuts so that you can also perform each type of submit using a
single key stroke. However, I'm finding that when I set the "label"
value and then call "submit()", I'm not seeing anything passed to my
CGI script.

[snip]

You don't need script for this at all.

<form action="label/" name="label_form" method="post">
<input type="submit" name="label" value="BEFORE" accesskey="b" />
<input type="submit" name="label" value="OVERLAP" accesskey="o" />
<input type="submit" name="label" value="AFTER" accesskey="a" />
</form>

But that doesn't make the "b", "o" and "a" keys work. That makes CTRL
+ALT+B, CTRL+ALT+O and CTRL+ALT+A work.

Steve
 
T

Thomas 'PointedEars' Lahn

Steven said:
But that doesn't make the "b", "o" and "a" keys work. That makes CTRL
+ALT+B, CTRL+ALT+O and CTRL+ALT+A work.

Because these shortcuts are not reserved (in Firefox) for other operations.

You see?


PointedEars
 
S

Steven Bethard

Because these shortcuts are not reserved (in Firefox) for other operations.

You see?

No, not really. Are you saying that there's something else I can do
to get "b" all alone to work? Or are you maybe saying that there's
nothing I can do to make that work?

Steve
 
S

Steven Bethard

I have a form with three submit buttons, each of which posts a
different value for my "label" parameter. I'm trying to add keyboard
shortcuts so that you can also perform each type of submit using a
single key stroke.

Here's what I'm doing now. I use a hidden input, and instead of
multiple submit buttons, I use button inputs that call Javascript code
to submit. Then I set the document.onkeyup to a function that checks
if any of the "hotkeys" have been pushed. It seems to work.

If there's an obviously better way of associating a *single* key press
with an action, please let me know.

<head>
<script type="text/javascript">
function add_label(label)
{
document.label_form.label.value = label;
document.label_form.submit();
}
function add_label_for_event(event)
{
if (!event)
var event = window.event;

if (event.keyCode)
code = event.keyCode;
else if (event.which)
code = event.which;
var character = String.fromCharCode(code);

if (character == "B")
add_label("BEFORE");
if (character == "O")
add_label("OVERLAP");
if (character == "A")
add_label("AFTER");
}
document.onkeyup = add_label_for_event;
</script>
</head>

<body>

<form action="label/" name="label_form" method="post">
<input type="hidden" name="label" />
<input type="button" value="BEFORE" onclick="add_label('BEFORE');"
accesskey="B" />
<input type="button" value="OVERLAP" onclick="add_label('OVERLAP');"
accesskey="O" />
<input type="button" value="AFTER" onclick="add_label('AFTER');"
accesskey="A" />
</form>
 
T

Thomas 'PointedEars' Lahn

Steven said:
No, not really. Are you saying that there's something else I can do
to get "b" all alone to work? Or are you maybe saying that there's
nothing I can do to make that work?

I am confident you can do something to make that work in Firefox. But I am
not particularly inclined to invest my free time to help you breaking the
UAs of your users. Because that would be the inevitable outcome of your
efforts.


PointedEars
 
S

Steven Bethard

I am confident you can do something to make that work in Firefox. But I am
not particularly inclined to invest my free time to help you breaking the
UAs of your users. Because that would be the inevitable outcome of your
efforts.

Perhaps I should put it into perspective then. This is part of a
research project where humans annotate text with interesting bits of
semantics. In annotation projects, it's crucial to minimize the number
of clicks, keys, etc. needed to perform a single annotation. That's
because the annotators are expected to look at thousands of pages in
quick succession, and those extra keys can add up quickly. Sure, I
could have created a stand-alone application instead of using a web-
based interface. But web-based interfaces are much easier to deploy
and update.

So while I may be "breaking" the user agent, that's only for a small
number of people who know that it's "broken" and who need it to be
"broken" in order to do their jobs efficiently. I really don't see the
problem here.

Steve
 
T

Thomas 'PointedEars' Lahn

Steven said:
Steven said:
[adding letters as shortcuts in Firefox]
I am confident you can do something to make that work in Firefox. But I am
not particularly inclined to invest my free time to help you breaking the
UAs of your users. Because that would be the inevitable outcome of your
efforts.

Perhaps I should put it into perspective then. This is part of a
research project where humans annotate text with interesting bits of
semantics. In annotation projects, it's crucial to minimize the number
of clicks, keys, etc. needed to perform a single annotation. That's
because the annotators are expected to look at thousands of pages in
quick succession, and those extra keys can add up quickly.

I don't see how the built-in shortcuts could not accomplish that. ISTM you
are trying to reinvent the wheel.
Sure, I could have created a stand-alone application instead of using a
web-based interface. But web-based interfaces are much easier to deploy
and update.

The terms "Stand-alone application" and "web-based interface" are not
antivalent anymore. Write an XUL application that accesses Web resources.
Users will have to install the Gecko engine and your application only.
This way you will have full control of all shortcuts you want to define.
And as you observe with Firefox and other Gecko-based apps, it is possible
to implement an (automatic) update facility.
So while I may be "breaking" the user agent, that's only for a small
number of people who know that it's "broken" and who need it to be
"broken" in order to do their jobs efficiently. I really don't see the
problem here.

Things will change with the next Firefox version, the next add-on, the next
localization, and the next crazy idea a VIP will come up with (such as "Why
does it break on my mobile device?"). I don't think you realize yet what
you are getting yourself into.


PointedEars
 
R

RobG

Perhaps I should put it into perspective then. This is part of a
research project where humans annotate text with interesting bits of
semantics. In annotation projects, it's crucial to minimize the number
of clicks, keys, etc. needed to perform a single annotation. That's
because the annotators are expected to look at thousands of pages in
quick succession, and those extra keys can add up quickly. Sure, I
could have created a stand-alone application instead of using a web-
based interface. But web-based interfaces are much easier to deploy
and update.

So while I may be "breaking" the user agent, that's only for a small
number of people who know that it's "broken" and who need it to be
"broken" in order to do their jobs efficiently. I really don't see the
problem here.

Steve

While I agree with Thomas about breaking UI's (and have been fighting
hard recently to prevent such in an intranet application for 4,000
users) I think it is acceptable if you *and your users* understand
what you are doing.

You could use the form's keyup event to detect the keystroke, then use
dispatchEvent[1] to "click" the submit button. It should respond as
if it's really been clicked by the user.

There's an example in the following thread:

<URL:
http://groups.google.com.au/group/c...k=gst&q=dispatchEvent&rnum=2#98cea9cdf065a524

1. Available in DOM 2 compliant browsers, if you want this to work in
IE, research fireEvent.

DOM 2 Events: dispatchEvent
<URL: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-dispatchEvent
MSDN fireEvent:
<URL: http://msdn2.microsoft.com/en-us/library/ms536423.aspx >
 
T

Thomas 'PointedEars' Lahn

RobG said:
[...]
1. Available in DOM 2 compliant browsers, if you want this to work in
IE, research fireEvent.

DOM 2 Events: dispatchEvent
<URL: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-dispatchEvent

MSDN fireEvent:
<URL: http://msdn2.microsoft.com/en-us/library/ms536423.aspx >

But, given that these methods require recent browsers, it would be more
reasonable to write an XUL application or a HTA instead.

But, even then: the OP wants "b", "o" and "a" to be shortcuts. The
interface will not be able to handle that unless he cancels the event
anywhere where the characters "b", "o", and "a" can be typed into, or
an accidental submit cannot be prevented.

Now, `keyup' is at least described in MSDN not be cancelable in the MSHTML
DOM. `keypress' can be canceled, but it is proprietary. So at least two
events have to be canceled for *every* *possible* element here to be
cross-browser. Etc. pp.

IOW: FU<submit><submit>R.


PointedEars
 
S

Steven Bethard

I don't see how the built-in shortcuts could not accomplish that.

Maybe I misunderstood the first time around? I thought the built-in
shortcuts were the ones that required holding the CTRL and ALT keys as
well. Is there a way to make the built-in shortcuts not require the
CTRL and ALT keys?
Things will change with the next Firefox version, the next add-on, the next
localization, and the next crazy idea a VIP will come up with (such as "Why
does it break on my mobile device?"). I don't think you realize yet what
you are getting yourself into.

I'm not too worried about future browser versions, etc. This is a
short-term project that I expect to complete by the end of September.
No one but myself and two others will see that page in the mean time.
FWIW, I've already heard back from the two of them that the one-key
shortcuts were a huge improvement.

All that said, I will take your suggestion and look into XUL when I
have some time.
 
T

Thomas 'PointedEars' Lahn

Steven said:
Maybe I misunderstood the first time around? I thought the built-in
shortcuts were the ones that required holding the CTRL and ALT keys as
well. Is there a way to make the built-in shortcuts not require the
CTRL and ALT keys?

Firefox being open source and free software, you can always compile and
install your own version. But I think you are better off with XUL; either
modify the XUL sources provided with your Firefox installation (if that is
possible), or create your own XUL application.

You should ask in a Firefox-related newsgroup.
I'm not too worried about future browser versions, etc. This is a
short-term project that I expect to complete by the end of September.
No one but myself and two others will see that page in the mean time.

And *after* that? You should ask yourself whether or not you are actually
coding for the trash can, and if not, what such an unwise approach will mean
for your reputation after the project.


PointedEars
 
S

Steven Bethard

[This is starting to get pretty off-topic, but I'll offer one final
response. Feel free to follow up off-list if you'd like.]

And *after* that? You should ask yourself whether or not you are actually
coding for the trash can, and if not, what such an unwise approach will mean
for your reputation after the project.

Nothing at all. The result of the research is the annotated corpus,
not the annotation software. So it's really okay if I'm "coding for
the trash can" as long as the code enables me to produce the corpus.
Because then, even though I might throw the code away, I won't be
throwing the corpus away.

Many people have tried to write general-purpose, reusable annotation
software. All attempts I know of have failed because you can never
customize the interface well enough to make things fast enough for
your particular task, and because the annotators are usually barely
computer literate and asking them to install anything is really a big
deal. If you're curious, some of the more popular (but still failed)
attempts are Callisto and WordFeak. Some day, maybe someone will
"solve" this problem, but rather than spend a year trying to develop a
general-purpose tool that's reusable, I've spent 3 days developing a
single-purpose tool that allows me to finish the corpus annotation as
early as possible.

Steve
 
B

Bill H

Maybe I misunderstood the first time around? I thought the built-in
shortcuts were the ones that required holding the CTRL and ALT keys as
well. Is there a way to make the built-in shortcuts not require the
CTRL and ALT keys?



I'm not too worried about future browser versions, etc. This is a
short-term project that I expect to complete by the end of September.
No one but myself and two others will see that page in the mean time.
FWIW, I've already heard back from the two of them that the one-key
shortcuts were a huge improvement.

All that said, I will take your suggestion and look into XUL when I
have some time.

Not to cause waves, but you could do that in flash, if all the person
is doing is reading text and then clicking on 1 of 3 buttons, a small
flash file could catch the keypresses and either send the information
on to your server, or access a javascript routine to do something on
the webpage.

Bill H
 
T

Thomas 'PointedEars' Lahn

Bill said:
Not to cause waves, but you could do that in flash, if all the person
is doing is reading text and then clicking on 1 of 3 buttons, a small
flash file could catch the keypresses and either send the information
on to your server, or access a javascript routine to do something on
the webpage.

If the solution were Flash in a common Web browser, J(ava)Script/ECMAScript
in a common Web browser was a solution as well, and a much better one since
no further plugin was required. The problem is not that it cannot be done
at all with JS/ES, but the undesired side-effects this will have in the
usual environment.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top