473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 10168
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sandyde2 | last post by:
Hi all, I get the tough problem and expect to get help.. In a html page, I dynamically created many forms which named as NO+business_id. In each form there are two submit buttons to...
5
by: José Carlos | last post by:
Hi. I am trying send a text value when click in an image. If i write: onClick="javascript:document.client.submit();" send all form, but i want to send only a input type text (name = cod),...
2
by: J. B. Moreno | last post by:
Is it possible to detect inside an onsubmit event /which/ button was pushed? I searched google and saw lots of suggestions for alternatives, but nobody outright saying it was impossible. At this...
5
by: Lau Lei Cheong | last post by:
Hello, Let's say that I have multiple submit buttons on a form (imagebuttons actually, but documentations say that <input type=image> which a called image buttons should behave like submit...
1
by: Bill_W_Stephens | last post by:
I have a complicated page with several submit buttons. I don't want to create multiple forms because much of the input is shared and the code is getting very ugly. However I would like to determine...
2
by: rudranee | last post by:
hello, How do i declare multiple submit buttons on a form? and how do i come to know on the next page which button has been clicked? Can i do it in JSP page? Please tell me.
7
by: ChristinaTIT | last post by:
Hi, I have a form containing ID Type Quantity Rate values. it should have two submit buttons which, when posted, will do the two different things in two different scripts.
7
by: aashishn86 | last post by:
hi ! how can i use multiple submit buttons in the same form i want to pass form values to different pages depending on which of the two submit button is clicked... thank's
3
by: printline | last post by:
Hello All I have a form with multiple submit buttons, where i would like to open in a new window when hitting one of the submit buttons. Can't seem to figure this out according to the code i'm...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.