Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 25th, 2004, 02:30 PM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Putting 2values in DB with 1 set of radio buttons

Hi, I have a (for me) difficult question:

I want to pass two values to my DB with one set of radio buttons. For instance:

Option1: price is 10 and length is 1
Option2: price is 20 and length is 3
Option3: price is 40 and length is 8

Both these variables go to different fields in my db. I tried having a hidden second radio button set, but I cannot connect it to the first one. Cause the pairs are always the same.

Is there a way of connecting two sets of radio buttons, I really need two sets.. What I want is that when I click on button 1 of the visible set button 1 of the hidden set is also clicked.

Hope someone can help

Thanks in advance
 
Old March 25th, 2004, 04:22 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's rather unclear what you're trying to accomplish. Can you elaborate a little bit about what you want your application to do?
It may also help if you tell us what server side scripting language you're using.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 25th, 2004, 06:56 PM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok: I have a form for people te get a subscribtion to my site. Now I want people to subscribe for a certain period (1,3,6,12 months) this is done with a couple of radio buttons.

In my Access) DB I have a table called "users" that stores username password etc etc.

I addedd two columns in the table called "months" and "amount".

Cause if somebody subscribe for, say 6 months, I want to store the price and the amount of months from now so the subscribtion is cancelled automatically when time is up. So with clicking on the radio button 6 months I have to say to my db: Fill months with 6 (months from now) and amount with 30. But I want this from one set of buttons. I use ASP and javascript.


Here is what I have now:

<input name="x_amount" type="radio" value="9,75" > 1 month
<input name="x_month" type="hidden" value="1" >

<input name="x_amount" type="radio" value="9,75" > 3 month
<input name="x_month" type="hidden" value="3" >

<input name="x_amount" type="radio" value="9,75" > 6 month
<input name="x_month" type="hidden" value="6" >

<input name="x_amount" type="radio" value="9,75" >12 month
<input name="x_month" type="hidden" value="12" >

I need the amount cause that's going to the CreditCard company And I need the months to store in my db to calculate the end date. When I run the above script it enters the price in the correct field and the amount field is filled with 1,3,6,12 and that should be one of them not all 4.

So you see it's nearly working but not quite...

Hope you can help.

Thanks again..

 
Old March 26th, 2004, 03:05 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try this

<input name="x_amount" type="radio" value="9,75" ID="Radio1" onclick="Hidden1.click();"> 1 month
<input name="x_month" type="radio" value="1" ID="Hidden1" style="visibility:hidden">

<input name="x_amount" type="radio" value="9,75" ID="Radio2" onclick="Hidden2.click();"> 3 month
<input name="x_month" type="radio" value="3" ID="Hidden2" style="visibility:hidden">

<input name="x_amount" type="radio" value="9,75" ID="Radio3" onclick="Hidden3.click();"> 6 month
<input name="x_month" type="radio" value="6" ID="Hidden3" style="visibility:hidden">

<input name="x_amount" type="radio" value="9,75" ID="Radio4" onclick="Hidden4.click();">12 month
<input name="x_month" type="radio" value="12" ID="Hidden4" style="visibility:hidden">

Regards,

PaS
 
Old March 26th, 2004, 03:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Right, I think I understand.

Since you're posting in a JavaScript forum, I assume it's OK to use JavaScript for the solution as well.

What you need to do is this:

1. Remove three hidden fields from your page, so you end up with only one field called x_month
2. On the click of each radio button, fire some JavaScript that sets the value for the x_month text box. This way, you can have four radio buttons and only one text box
3. At the server, read the value from the x_month textbox. It should contain only one value.

At the server, you also have to validate the x_month and x_amount again. It would be too easy for a user to submit a hand-made form that pays for 1 month, but passes 12 or 120 to the x_month box.

Here's some code that does what I described:
Code:
<form>
    <input name="x_amount" 
        onclick="document.forms[0].x_month.value='3';" 
        type="radio" value="9,75">
    <input name="x_amount" 
        onclick="document.forms[0].x_month.value='6';" 
        type="radio" value="9,75">
    <input name="x_amount" 
        onclick="document.forms[0].x_month.value='9';" 
        type="radio" value="9,75">
    <input name="x_amount" 
        onclick="document.forms[0].x_month.value='12';" 
        type="radio" value="9,75">
    <input name="x_month" id="x_month" type="hidden">
</form>
To see if it works, change the type of x_month tp text instead of hidden, and you'll see it gets a different value when you click one of the radio buttons.

Is this what you were looking for?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation Radio Buttons jonsey Classic ASP Professional 1 June 6th, 2007 11:48 PM
InfoPath radio buttons MichaelBjerke Infopath 0 May 29th, 2007 10:27 AM
Radio buttons disappear JoeBob49 ASP.NET 2.0 Basics 2 November 27th, 2006 09:57 AM
How to use the radio buttons? ben_VB VB.NET 2002/2003 Basics 1 January 18th, 2005 12:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.