473,241 Members | 1,429 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,241 software developers and data experts.

Radio buttons conditional submit

Here's A piece of my code:

<form action="dimensions.php" method="POST">
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Customer" checked> Customer</br>
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Employee"> Project Manager</br>
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Vendor" > Vendor</br>
<br><input type="submit" name="submitknop" value="Change"></br>

What I want here is that when I click on the submit button, the 'form
action' target should be changed to an other webpage depending on the
radio button that has been selected. So, if I selected 'Customer',
another page should be opened than when I select 'Vendor'. I spent a
whole day on it (also trying JS etc.) and can't get it to work.
Anyone to help me?
Jul 23 '05 #1
4 2289
"Sjon" <re*****@gmail.com> skrev i meddelandet
news:41**************************@posting.google.c om...
Here's A piece of my code:

<form action="dimensions.php" method="POST">
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Customer" checked> Customer</br>
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Employee"> Project Manager</br>
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Vendor" > Vendor</br>
<br><input type="submit" name="submitknop" value="Change"></br>

What I want here is that when I click on the submit button, the 'form
action' target should be changed to an other webpage depending on the
radio button that has been selected. So, if I selected 'Customer',
another page should be opened than when I select 'Vendor'. I spent a
whole day on it (also trying JS etc.) and can't get it to work.
Anyone to help me?


1. Give the form a name attribute to be able to reference it:
<form name="myform" action="dimensions.php" method="POST">

2. Add an onsubmit handler:

// In the form tag:
<form name="myform" action="dimensions.php" method="POST" onsubmit="return
submitForm();">

// in the <head>:
<script type=text/javascript">
function submitForm(){

var theForm = document.forms["myform"];
if(theForm){
if(theForm.categorie[0].checked){
theForm.action="blah1.htm";
}
else if(theForm.categorie[1].checked){
theForm.action="blah2.htm";
}
else if(theForm.categorie[2].checked){
theForm.action="blah3.htm";
}
}

return true;
}
</script>

Untested, but you can see how it's supposed to work. (You do have a closing
</form> tag, right?)

Joakim Braun

Jul 23 '05 #2
> "Sjon" <re*****@gmail.com> skrev i meddelandet
news:41**************************@posting.google.c om...
Here's A piece of my code:

<form action="dimensions.php" method="POST">
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Customer" checked> Customer</br>

<snip>

By the way, there's no such thing as a closing </br>.

Joakim Braun
Jul 23 '05 #3
On Tue, 14 Dec 2004 10:15:56 +0100, Joakim Braun
<jo**********@jfbraun.removethis.com> wrote:
"Sjon" <re*****@gmail.com> skrev i meddelandet
news:41**************************@posting.google.c om...
[snip]
<br><input type="radio" style="background : #84c7e8"
name="categorie" value="Customer" checked> Customer</br>
These BR elements (and as Joakim said, BR doesn't have a closing tag - in
fact, it's forbidden) should be LABELs. If you styled them as

label {
display: block;
}

you should end up with the same layout, only now it's using appropriate
mark-up.

[snip]
What I want here is that when I click on the submit button, the 'form
action' target should be changed to an other webpage depending on the
radio button that has been selected. [...]
Anyone to help me?


This is really something that should be performed server-side, but I
assume from the content that this isn't for the Web anyway.
1. Give the form a name attribute to be able to reference it:
<form name="myform" action="dimensions.php" method="POST">
Why? There's no need to and if anything, it should be an id, not a name.
If you're trying to support NN4, add both.
2. Add an onsubmit handler:

// In the form tag:
<form name="myform" action="dimensions.php" method="POST"
onsubmit="return submitForm();">

// in the <head>:
<script type=text/javascript">
function submitForm(){
var theForm = document.forms["myform"];
if(theForm){
if(theForm.categorie[0].checked){
theForm.action="blah1.htm";
}
else if(theForm.categorie[1].checked){
theForm.action="blah2.htm";
}
else if(theForm.categorie[2].checked){
theForm.action="blah3.htm";
}
}
return true;
}


Or better:

function submitForm(form) {var categorie = form.elements.categorie;
if(categorie[0].checked) {
form.action = 'blah1.html';
} else if(categorie[1].checked) {
form.action = 'blah2.html';
} else if(categorie[1].checked) {
form.action = 'blah3.html';
} else {
alert('Please select a category.');
return false;
}
}

<form action="dimensions.php" method="post"
onsubmit="return submitForm(this);">

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
<OT>

Joakim Braun wrote:
"Sjon" <re*****@gmail.com> skrev i meddelandet
news:41**************************@posting.google.c om...
> Here's A piece of my code:
>
> <form action="dimensions.php" method="POST">
> <br><input type="radio" style="background : #84c7e8" name="categorie"
> value="Customer" checked> Customer</br>

<snip>

By the way, there's no such thing as a closing </br>.


By the way, there is in XHTML; however the `br' element's content model
is empty (<br/> or <br></br>).

</OT>
PointedEars
--
In theory, practice and theory are the same, but in practice they are
different -- Larry McVoy
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Owen Funkhouser | last post by:
I have a form with three radio options. And I have three buttons: <input type="submit" name="mainform_action" value="Edit Data"> <input type="submit" name="mainform_action" value="View Data">...
15
by: JR | last post by:
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...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
3
by: Ken Varn | last post by:
This is probably a simple question, but I am new to this so bear with me. I have a ASP.NET form that has a checkbox and a 2 radio buttons. When the checkbox is checked, the 2 radio buttons are...
1
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
8
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked)...
7
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.