468,133 Members | 1,168 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

Multiple onclick=submit() need to pass name????

I have a number of applications where I want to have many
onclick='submit()' attached to different 'elements' on a single form
..... which sends the form to a CGI "script" which does all the
validation. The problem is.. how can I code the submit()s so the CGI's
form collection knows which 'element' was clicked??

I am NOT permitted to use <input type=image...> or any "button" that
browsers produce for forms.... the reasons are all client related
;o)))

If I can put a string inside the parentheses (i.e.
onclick='submit("thisbutton")'.... and have it's characters included in
the POST information to the CGI.. It will work for me. Can this be
done?? how?

Jul 23 '05 #1
11 9849
charlie_M wrote:
I have a number of applications where I want to have many
onclick='submit()' attached to different 'elements' on a single form
..... which sends the form to a CGI "script" which does all the
validation. The problem is.. how can I code the submit()s so the CGI's
form collection knows which 'element' was clicked??

I am NOT permitted to use <input type=image...> or any "button" that
browsers produce for forms.... the reasons are all client related
;o)))

If I can put a string inside the parentheses (i.e.
onclick='submit("thisbutton")'.... and have it's characters included in
the POST information to the CGI.. It will work for me. Can this be
done?? how?


onclick="someFunction(this.id)"

<input type="text" name="inputUsed">

function someFunction(inputID){
document.forms['formName'].elements['inputUsed'].value = inputID;
document.forms['formName'].submit();
}

And in each of your "elements" have an ID attribute that identifies it.

In other words, instead of using the element to submit the form, have
the element give a function its ID attribute, set a form field to that
value, then submit the form. Then, the server can pick up the value of
inputUsed to determine what element was used to submit the form.

And I won't go into the ludicrous idea of setting up a webpage the way
you are describing. If your client is that ignorant, its *your* job as
the professional to educate them on the pitfalls of the design.
Accessibility, non-JS, and many other issues make the entire approach a
bad design before you have ever started.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
Lee
charlie_M said:

I have a number of applications where I want to have many
onclick='submit()' attached to different 'elements' on a single form
.... which sends the form to a CGI "script" which does all the
validation. The problem is.. how can I code the submit()s so the CGI's
form collection knows which 'element' was clicked??

I am NOT permitted to use <input type=image...> or any "button" that
browsers produce for forms.... the reasons are all client related
;o)))

If I can put a string inside the parentheses (i.e.
onclick='submit("thisbutton")'.... and have it's characters included in
the POST information to the CGI.. It will work for me. Can this be
done?? how?


1. It's your responsibility to point out to your clients that
they're making a potentially serious mistake by not allowing
the form to be submitted if Javascript is disabled.

2.
onclick="document.forms[0].myHiddenField.value='thisButton';document.forms[0].submit()"

Jul 23 '05 #3
OK.. 2 things I do not understand...

1. If I (as the CGI) receive an ID.. how do I know WHICH submit() it
was ?? Knowing that it was ID #5 tells me what??? This occured to me in
browsing other people's posts about this and similar topics. I need to
pass a NAME and somehow have it included in the form data return. The
CGI can then figure it out.

2. How do I get the form's data to be submitted with the form data and
the id(s)?? From your example. I think I see how this is done. Can
this be used more simply??? .... I only ever have 1 form... like???

function someFunction(NameNotId){
thisform.elements['NameNotId'].value = 'XX';
thisform.submit();
}

I am only 'guessing' about the 'thisform' syntax..... does this work??

TIA
Chuck

Jul 23 '05 #4
You are right Lee.... and I have. These applications are very complex
and the client has a bug in his butt about looking a "paricular way"
and javascript must serve. The apps are written in Visual Fox and run
on a PC based blade server. We can not change how the server side works
and M$'s buttons and Netscape buttons are abhorent to the client, I am
attempting to get a <TD> to work as a submit button with appropriate
stylesheet colorings and rollovers. These are not public access apps...
they are for logged-in publishers and the ilk and we get to say how
they access the app!!!

Thanks
Chuck

Jul 23 '05 #5
charlie_M wrote:
OK.. 2 things I do not understand...

1. If I (as the CGI) receive an ID.. how do I know WHICH submit() it
was ?? Knowing that it was ID #5 tells me what??? This occured to me in
browsing other people's posts about this and similar topics. I need to
pass a NAME and somehow have it included in the form data return. The
CGI can then figure it out.
Pass the name itself.

<input type="button" name="button1" value="Button Number 1"
onclick="someFunction(this.name)">

function someFunction(elemName){
myForm = document.forms['formName'];
myForm.elements['fieldName'].value = elemName;
myForm.submit();
}

Then, the server looks at the value of the field named "fieldName" and
it will know the name of the element that was clicked to submit the
form. Test it :)
2. How do I get the form's data to be submitted with the form data and
the id(s)?? From your example. I think I see how this is done. Can
this be used more simply??? .... I only ever have 1 form... like???

function someFunction(NameNotId){
thisform.elements['NameNotId'].value = 'XX';
thisform.submit();
}

I am only 'guessing' about the 'thisform' syntax..... does this work??


Only in IE if the name of the form is thisform. See above.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #6
"charlie_M" <cm******@comcast.net> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
OK.. 2 things I do not understand...

1. If I (as the CGI) receive an ID.. how do I know WHICH submit() it
was ?? Knowing that it was ID #5 tells me what??? This occured to me
in
browsing other people's posts about this and similar topics. I need to
pass a NAME and somehow have it included in the form data return. The
CGI can then figure it out.


Don't rely on client-side JavaScript at all:

<%
Response.write(Request.value('a1') + ';' + Request.value('d1'));
%>
<form>
<input type="submit" name="a1" value="Add">
<input type="submit" name="d1" value="Delete">
</form>

If I click -a1- I get Add:null, if I click -d1- I get null;Delete.

It would be simple matter to loop on the server looking for a known
input name that has a non-null value, then act on it... for safety you
may want to pass another hidden input that contains the number
of -a#-, -d#- items, otherwise you wouldn't know when to stop checking
on the server.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Grant..

I stated earlier I cannot change how the server side works. Also... I
cannot use any sort of BUTTON... i.e "<input type=submit...>

It would be a VERY simple matter to catch the value if it were
there.... but javascript.submit() does not automatically provide it ..
which is why the "original" question was posed...........?????

The ANSWER.. BTW has been implimented and it works with some
limitations:

onClick="document.forms[0].MYBUTTON.value='FLASHW';document.forms[0].submit()"

which requires I supply a hidden variable in the form named "MYBUTTON"
and my CGI will pickup on it if this submit() element is clicked.
BTW... this "element" is simply a <TD> with stylesheet rollover-type
elements..... and there are a number of them. This satisfies the
client, looks really impressive, works like a charm, was the answer to
the original question. ;o)))

Thanks to all that contributed...
Chuck

Jul 23 '05 #8
charlie_M wrote:
[...] M$'s buttons and Netscape buttons are abhorent to the client,
Then use input[type="image"] elements and create your own buttons.
I don't see a problem here, especially if it's not a "public app".
I am attempting to get a <TD> to work as a submit button with
appropriate stylesheet colorings and rollovers. [...]
Why not format an input[type="submit"] that way?
[...]
!!


Looks like you've lost something.
PointedEars
Jul 23 '05 #9


Thomas 'PointedEars' Lahn wrote:
charlie_M wrote:
[...] M$'s buttons and Netscape buttons are abhorent to the client,


Then use input[type="image"] elements and create your own buttons.
I don't see a problem here, especially if it's not a "public app".
I am attempting to get a <TD> to work as a submit button with
appropriate stylesheet colorings and rollovers. [...]


Why not format an input[type="submit"] that way?
[...]
!!


Looks like you've lost something.
PointedEars


I don't know why your ears are pointed.. but your eyes are failing you
;o))

REF: the original message says "I am NOT permitted to use <input
type=image...> or any "button" that browsers produce for forms.... the
reasons are all client related"... therefore: ??? The <TD> is what they
wanted... and I posted the solution.

Thanks
Chuck

Jul 23 '05 #10
charlie_M wrote:
<snip>
REF: the original message says "I am NOT permitted to
use <input type=image...> or any "button" that browsers
produce for forms.... the reasons are all client
related"... therefore: ??? The <TD> is what they
wanted... and I posted the solution.


The 'therefor' is not valid. Experience suggests that such a requirement
on the part of a client is usually the product of a misconception, or a
lack of thought. And so it is usually an examination of the reasoning
behind the requirement that exposes the real solution.

Of course if the reasoning behind an apparently bad decision is never
revealed then no useful progress can be made, but generally TD elements
make very poor GUI components.

Richard.
Jul 23 '05 #11
charlie_M wrote:
Thomas 'PointedEars' Lahn wrote:
charlie_M wrote:
> [...] M$'s buttons and Netscape buttons are abhorent to the client,


Then use input[type="image"] elements and create your own buttons.
I don't see a problem here, especially if it's not a "public app".
> I am attempting to get a <TD> to work as a submit button with
> appropriate stylesheet colorings and rollovers. [...]


Why not format an input[type="submit"] that way? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [...]

[...]
REF: the original message says "I am NOT permitted to use <input
type=image...> or any "button" that browsers produce for forms.... the
reasons are all client related"... therefore: ??? The <TD> is what they
wanted...


They only wanted it because they do not know better, and they certainly
do not know that using `td' elements as controls will reduce the people
in the target group and increase maintenance costs since support for
client-side scripting is not guaranteed and neither is the required DOM
support. It is your job to change that and if you do not do it, you
behave incompetent (and deserve all what must follow in the mid-term
and long-term).
PointedEars
--
But he had not that supreme gift of the
artist, the knowledge of when to stop.
-- Sherlock Holmes
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Josť Carlos | last post: by
2 posts views Thread by J. B. Moreno | last post: by
5 posts views Thread by Lau Lei Cheong | last post: by
2 posts views Thread by rudranee | last post: by
7 posts views Thread by aashishn86 | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.