Radio Submit Button Problem

J

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!!!
 
S

Steven Daedelus

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?
 
J

Jack Black

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.
 
B

bruce

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.
 
T

Thomas 'PointedEars' Lahn

JR said:
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
 
K

Kien

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
 
S

Steven Daedelus

Thomas 'PointedEars' Lahn said:
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.
 
M

Matt Kruse

Steven said:
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 ;)
 
B

bruce

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.
 
S

Steven Daedelus

Matt Kruse said:
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?
 
T

Thomas 'PointedEars' Lahn

Steven said:
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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn



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.
 
J

JR

</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
 
M

Michael Winter

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
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top