By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,969 Members | 2,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,969 IT Pros & Developers. It's quick & easy.

Radio Submit Button Problem

P: n/a
JR
Hi. I hope someone out there who is more versed with JavaScript than
I can help me with the following annoying problem. Here's the
problem.

I have a form with the following layout:

Column A Column B Column C
data 4 radio buttons more data
.... ... ...
.... ... ...

The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script. The problem is that I
need to know which particular radio button triggered the onClick
event, because when I receive the form data, I only want to process
the row of data for which an event was triggered. As the script is
now, I just receive everything from the form, without knowing which
row to actually process. The one thing I thought about trying was to
call a function with the onClick event that would receive a given row
id (1 through up to 279), and the use document.write to create a
hidden value for just that id. I don't know if this is workable,
though. Am I on the right track with this idea? Is this doable, or
should I think about trying a different approach?

Thanks!!!
Jul 23 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
In article <b3*************************@posting.google.com> ,
jr*********@yahoo.com (JR) wrote:
Hi. I hope someone out there who is more versed with JavaScript than
I can help me with the following annoying problem. Here's the
problem.

I have a form with the following layout:

Column A Column B Column C
data 4 radio buttons more data
... ... ...
... ... ...

The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script. The problem is that I
need to know which particular radio button triggered the onClick
event, because when I receive the form data, I only want to process
the row of data for which an event was triggered. As the script is
now, I just receive everything from the form, without knowing which
row to actually process. The one thing I thought about trying was to
call a function with the onClick event that would receive a given row
id (1 through up to 279), and the use document.write to create a
hidden value for just that id. I don't know if this is workable,
though. Am I on the right track with this idea? Is this doable, or
should I think about trying a different approach?

Thanks!!!


Don't think you can do document.write after the page has rendered.

Here's what I'd do:

Put in a hidden input field. Create a function to handle the onClick
event. Pass the id of the radio button to the function. The function
then sets the value of the hidden field to whatever the id is.

Make sense?
Jul 23 '05 #2

P: n/a
Thanks for the reply. I'll give this idea a try. It sounds like a
workable solution. If it does work, I'll post the code in my next
reply-someone else out there may have the same problem.

Thanks again.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a
jr*********@yahoo.com (JR) wrote in message news:<b3*************************@posting.google.c om>...
Hi. I hope someone out there who is more versed with JavaScript than
I can help me with the following annoying problem. Here's the
problem.

I have a form with the following layout:

Column A Column B Column C
data 4 radio buttons more data
... ... ...
... ... ...

The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script. The problem is that I
need to know which particular radio button triggered the onClick
event, because when I receive the form data, I only want to process
the row of data for which an event was triggered. As the script is
now, I just receive everything from the form, without knowing which
row to actually process. The one thing I thought about trying was to
call a function with the onClick event that would receive a given row
id (1 through up to 279), and the use document.write to create a
hidden value for just that id. I don't know if this is workable,
though. Am I on the right track with this idea? Is this doable, or
should I think about trying a different approach?

Thanks!!!


From what I see, the only way is to have a loop, and check each
radio button for the "checked" property. If you give the radio buttons
the same name, they form an array, so you can use a for-loop.
Jul 23 '05 #4

P: n/a
JR wrote:
The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script.
What about users without support for client-side scripting?
The problem is that I need to know which particular radio button
triggered the onClick event, because when I receive the form data,
I only want to process the row of data for which an event was triggered.


Use several submit buttons with the different name and/or different values.
<input type="image"> may be useful as well, that displays a graphical
submit button, if supported (since HTML 4 IIRC). Then test against the name
or the value of the submit button server-side.

Or use several form elements with different "action" attribute values.

Anything else is considered harmful.
PointedEars
Jul 23 '05 #5

P: n/a
Hi,
I would collect the data input by user, stick them into another form
and submit that form according to the thing that was clicked.

<form name=F1>
<input type=radio name=Rad1
onclick=Chk(this.form,this.name,this.value)>
<input type=button value="OK"
onclick=Chk(this.form,"button","button")>
</form>
.....
<form name=F2 action=Onecgi.cgi>
<input type=hidden name=Val1>
<input type=hidden name=Val2>
</form>
<form name=F3 action=Twocgi.cgi>
<input type=hidden name=Val1>
<input type=hidden name=Val2>
</form>
<script>

function Chk(F,Nm,Val){

if(Nm=="button"{ // submit button - fill F2 then submit it
to Onecgi
document.F2.Val1.value=whatever
document.F2.Val2.value=whatever
document.F2.submit()
}

else{ //radio button - fill F3 then submit it to
Twocgi
document.F3.Val1.value=Nm
document.F3.Val2.value=Val
document.F3.submit()
}

}
</script>

Maybe crude and very redundant but it's 7AM and my brain is not
working ...

HTH

Kien

jr*********@yahoo.com (JR) wrote in message news:<b3*************************@posting.google.c om>...
Hi. I hope someone out there who is more versed with JavaScript than
I can help me with the following annoying problem. Here's the
problem.

I have a form with the following layout:

Column A Column B Column C
data 4 radio buttons more data
... ... ...
... ... ...

The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script. The problem is that I
need to know which particular radio button triggered the onClick
event, because when I receive the form data, I only want to process
the row of data for which an event was triggered. As the script is
now, I just receive everything from the form, without knowing which
row to actually process. The one thing I thought about trying was to
call a function with the onClick event that would receive a given row
id (1 through up to 279), and the use document.write to create a
hidden value for just that id. I don't know if this is workable,
though. Am I on the right track with this idea? Is this doable, or
should I think about trying a different approach?

Thanks!!!

Jul 23 '05 #6

P: n/a
In article <40**************@PointedEars.de>,
Thomas 'PointedEars' Lahn <Po*********@nurfuerspam.de> wrote:
JR wrote:
The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script.


What about users without support for client-side scripting?


You can please all the people some of the time, and some of the people
all the time, but you can't please all the people all the time.
Jul 23 '05 #7

P: n/a
Steven Daedelus wrote:
You can please all the people some of the time, and some of the people
all the time, but you can't please all the people all the time.


Careful... uttering that truism around here can get you blacklisted ;)

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 23 '05 #8

P: n/a
jr*********@yahoo.com (JR) wrote in message news:<b3*************************@posting.google.c om>...
Hi. I hope someone out there who is more versed with JavaScript than
I can help me with the following annoying problem. Here's the
problem.

I have a form with the following layout:

Column A Column B Column C
data 4 radio buttons more data
... ... ...
... ... ...

The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script. The problem is that I
need to know which particular radio button triggered the onClick
event, because when I receive the form data, I only want to process
the row of data for which an event was triggered. As the script is
now, I just receive everything from the form, without knowing which
row to actually process. The one thing I thought about trying was to
call a function with the onClick event that would receive a given row
id (1 through up to 279), and the use document.write to create a
hidden value for just that id. I don't know if this is workable,
though. Am I on the right track with this idea? Is this doable, or
should I think about trying a different approach?

Thanks!!!

Just capture whatever data you need inside hidden fields (be it
data, or id's, or names of controls, whatever), before you submit the
form.
Jul 23 '05 #9

P: n/a
In article <c9********@news2.newsguy.com>,
"Matt Kruse" <ne********@mattkruse.com> wrote:
Steven Daedelus wrote:
You can please all the people some of the time, and some of the people
all the time, but you can't please all the people all the time.


Careful... uttering that truism around here can get you blacklisted ;)


I know it. It's just that sometimes I can't resist pointing out the
obvious...

Do you ever get the feeling that a lot of the most severe compliance
fascists don't have clients?
Jul 23 '05 #10

P: n/a
Steven Daedelus wrote:
In article <40**************@PointedEars.de>,
Thomas 'PointedEars' Lahn <Po*********@nurfuerspam.de> wrote:


Please do not write attribution novels, see e.g.
<http://www.holgermetzger.de/netscape/usenet.html>
<http://netmeister.org/news/learn2quote.html>
JR wrote:
> The form does have a submit button that leads to a given CGI script.
> The form also has submit buttons as onClick events inside of the radio
> buttons, that point to a different CGI script.


What about users without support for client-side scripting?


You can please all the people some of the time, and some of the people
all the time, but you can't please all the people all the time.


But you can do easily here.
PointedEars
Jul 23 '05 #11

P: n/a
Steven Daedelus wrote:
Do you ever get the feeling that a lot of the most severe compliance ^^^^^^^^^^ fascists don't have clients?

^^^^^^^^
Godwin's Law. You lose.
PointedEars, F'up2 where it belongs
Jul 23 '05 #12

P: n/a
JR
ca*********@hotmail.com (Kien) wrote in message news:<16**************************@posting.google. com>...
</script>

Maybe crude and very redundant but it's 7AM and my brain is not
working ...

HTH

Kien


If it's crude and redundant, but works, I'm all for it! Thanks very
much for the solution. I found that the best solution for my
particular problem was right along the lines of your script. I call a
given function when the user selects a certain radio button, and pass
to this function data for only the row I want to process. I then
append this data string to my script path, i.e.
path/program.cgi?javascript_params, and then submit the form. This
way, I do get all of the data from the form when it is submitted, but
I know which row of data to process in the receiving script.

Thanks to everyone for the suggestions.

JR
Jul 23 '05 #13

P: n/a
JRS: In article <40************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@nurfuerspam.de> posted at Wed, 2 Jun 2004 01:54:48 :
Steven Daedelus wrote:
In article <40**************@PointedEars.de>,
Thomas 'PointedEars' Lahn <Po*********@nurfuerspam.de> wrote:


Please do not write attribution novels, see e.g.
<http://www.holgermetzger.de/netscape/usenet.html>
<http://netmeister.org/news/learn2quote.html>


Son-of-RFC1036 (1994) refers to "attribution lines" containing more
than just a name. Note the implication that more than one physical line
may be
needed.

A draft RFC by C H Lindsey (a well-known News expert), dated August
2002, envisages a line containing name, E-address, newsgroup, Message-
ID, date, and time; and that it may be folded. It is called draft-ietf-
usefor-article-08.txt

Therefore, your customary tedious insistence on minimal attributions is
contrary to respected recent thinking.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #14

P: n/a
JR wrote:
Hi. I hope someone out there who is more versed with JavaScript than
I can help me with the following annoying problem. Here's the
problem.

I have a form with the following layout:

Column A Column B Column C
data 4 radio buttons more data
... ... ...
... ... ...

The form does have a submit button that leads to a given CGI script.
The form also has submit buttons as onClick events inside of the radio
buttons, that point to a different CGI script. The problem is that I
need to know which particular radio button triggered the onClick
event, because when I receive the form data, I only want to process
the row of data for which an event was triggered. As the script is
now, I just receive everything from the form, without knowing which
row to actually process. The one thing I thought about trying was to
call a function with the onClick event that would receive a given row
id (1 through up to 279), and the use document.write to create a
hidden value for just that id. I don't know if this is workable,
though. Am I on the right track with this idea? Is this doable, or
should I think about trying a different approach?

Thanks!!!

Since this conversation seems to have drifted from the point, I'll do my
part to direct it back.

Message author bruce seemed to have the answer to the original question
which allows JR to keep his form as it is. I intend to include code
(not tested, just making it up as I type) to support bruce's idea.
<head>....
<script>
function testButtons(buttonArray)
{
len = buttonArray.length
for(i=0;i<len;i++)
{
if(buttonArray[i].checked)
{
widelyVisibleVariable = i;
return true;
{
}
}
</script>
......</head>

<body>
....
<form name=someName action=someServer onSubmit=testButtons(buttonGroupName)>
....
</form>
</body>
Jul 23 '05 #15

P: n/a
On 30/03/2005 17:55, Jeff Sandler wrote:

[snip]
Since this conversation seems to have drifted from the point, I'll do my
part to direct it back.


This that conversation is almost a year old, was it really necessary
to resurrect it?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.