How can I capture 3 values to a database from a single radio button in ASP ?

I have a page that has 2 radio-buttons, 1 for each product.
I need to capture the value(Price) of the radio button, reference number (different for both products) and item name (same for both products) when

How do I capture these item. My current code caputures both the hidden values of both products when I call it on the next page. My code is as follows:

<INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3"></FONT></TD></tr><TR>
<TD vAlign="top" width="30%" bgcolor="#c0c0c0"></TD>
<TD vAlign="top" width="25%" bgcolor="#c0c0c0">
<input type="hidden" value="CSP Manual" name="item" id="Hidden1">
<input type="hidden" value="P12001" name="reference" id="Hidden2">
<INPUT type="radio" value="375" name="amount"> <B><FONT face="Tahoma" color="#000000" size="1">
Members</FONT></B></TD>
<TD vAlign="top" width="25%" bgcolor="#c0c0c0">
<input type="hidden" value="CSP Manual" name="item" id="Hidden3">
<input type="hidden" value="P12002" name="reference" id="Hidden4">
<INPUT type="radio" value="600" name="amount"><FONT size="2">&nbsp;</FONT><B>&nbsp;</B><FONT face="Tahoma" size="2">
</FONT><FONT face="Tahoma" color="#000000" size="1"><B>Non-members</B></FONT>
LVL 5
zamorinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VincentPugliaCommented:
Hi,

Since I don't know exactly what you mean, I'm only 'alerting the value' -- change that line to whatever you need.


function doit(formObj)
{
  for (i = 0; i < formObj.length;i++)
  {
      el = formObj.elements[i]
      if (el.name == 'amount' &&  el.checked)
      {
        alert(el.value);
         break;
      }

  }
}

//-->
</script>
</head>
<body>
<form name='a' >
<table border="1"><tr><td>
<INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3" onclick='doit(document.a)'>
0
zamorinAuthor Commented:
Let me try to be clearer;

I have a page whereby the user car choose a product depending on his location.
I want to caputure 3 values from a single radio button :
1. Product Price
2. Product  Name (hidden field)
3. Reference number (hidden field)

so that I can display it on the next page, which lets the user view the 3 details above and confirm the purchase.

With the current code  I assign the radio-button value as the price and that gets displayed on the next page. But the Product name and description captures both the items name and reference number, but I only want the details of the selected product to be displayed on the next page.

The nex page code is as follows:

<input type="text" name="reference"  value="<%=Request.Form("reference")%>>
<input type="text" name="item"  value="<%=Request.Form("item")%>>
<input type="text" name="amount"  value="<%=Request.Form("amount")%>>

The output page for the above code looks like this:

Reference No.: P12001, P12002
Publication : CSP Manual, CSP Manual
Amount : 600.00

0
poopallCommented:
Store the value of the radio button as follows:  "Value1:Value:2Value3"

On the next page use the split function in asp to seperate the value

see http://www.asp-help.com/getstarted/ms/vbscript/166.asp for details of this function


This should do the trick.
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

zamorinAuthor Commented:
poopall,

What would be the exact code?

I am very new to asp, and also how do I call it in the next page?
thanks
0
poopallCommented:
I assume that you know how to transfer values from one bage to another, assuming the submit function passes a value as follows:
http://blablabal/nextpage?button3=abc%3Acde%3Aefg,  dont get confused as the %3A represents a colon (:)

So what is passed to the next page is abc:cdx:efg



Rought example of how you can then split the button variable into 3 parts
<%

xStr = Request("button3")
xaray = split(xstr,":")
for i = 0 to uBound(xaray)
      response.write(xaray(i))
      response.write("<br>")
next
%>

I hope this explain ?
0
VincentPugliaCommented:
1) you only need 2 hidden fields:
2)
function doit(formObj)
{
  for (i = 0; i < formObj.length;i++)
  {
      el = formObj.elements[i]
      if (el.name == 'amount' &&  el.checked)
      {
         formObj.hidden1.value = (0 == i) ? 'CSPManual' : "CSPDeluxeManual";
         formObj.hidden2.value = (0 == i) ?  ' P12001' : 'P12002'
         break;
      }
  }
}

the submission should send only the checked radio button & you can then access its value just as you access the values of hidden1 & 2

Vinny
0
YZlatCommented:
index.asp
-----------
<html>
<body>

<form name="myForm" method="post" action="preview.asp">
<table>
<tr>
      <TD>
            <INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3" onClick="document.myForm.submit()">
      </TD>
</tr>
<TR>
      <TD vAlign="top" width="30%" bgcolor="#c0c0c0"></TD>
      <TD vAlign="top" width="25%" bgcolor="#c0c0c0">
            <input type="hidden" value="CSP Manual" name="item" id="Hidden1">
            <input type="hidden" value="P12001" name="reference" id="Hidden2">
            <INPUT type="radio" value="375" name="amount">
                   <B><FONT face="Tahoma" color="#000000" size="1">Members</FONT></B>
      </TD>
      <TD vAlign="top" width="25%" bgcolor="#c0c0c0">
            <input type="hidden" value="CSP Manual" name="item" id="Hidden3">
            <input type="hidden" value="P12002" name="reference" id="Hidden4">
            <INPUT type="radio" value="600" name="amount">
                  
            <FONT face="Tahoma" color="#000000" size="1"><B>Non-members</B></FONT>
      </TD>
</tr>
</table>
</form>
</body>
</form>
</body>
</html>


0
ourselvesCommented:
Try the 2 ASP pages below:

ChooseItem.asp:
<HTML>
<BODY>
<CENTER>
<FONT FACE=ARIAL SIZE=3>
<FORM name="ChooseItem" method="POST" action="Preview.asp">
<TABLE BORDER=0 WIDTH=60%>
      <TR>
            <TD COLSPAN=2>
                  <INPUT TYPE=SUBMIT VALUE="Submit">
            </TD>
      </TR>
      <TR>
            <TD>
                  <INPUT TYPE="RADIO" VALUE="375" name=Item>Member
            </TD>
            <TD>
                  <INPUT TYPE=HIDDEN VALUE="P12001" name=txtMember>
                  <INPUT TYPE=HIDDEN VALUE="CSP Manual" name=txtPubMember>
            </TD>
      </TR>
      <TR>
            <TD>
                  <INPUT TYPE="RADIO" VALUE="600" name=Item>Non Member
            </TD>
            <TD>
                  <INPUT TYPE=HIDDEN VALUE="P12002" name=txtNonMember>
                  <INPUT TYPE=HIDDEN VALUE="CSP Manual" name=txtPubNonMember>
            </TD>
      </TR>
</TABLE>
</FORM>
</FONT>
</CENTER>
</BODY>
</HTML>

Preview.asp:
<%
      amount = Request.Form("Item")
      if (amount=375) then
            publication=Request.Form("txtPubMember")
            reference=Request.Form("txtMember")
      end if
      
      if (amount=600) then
            publication=Request.Form("txtPubNonMember")
            reference=Request.Form("txtNonMember")
      end if
      
      Response.Write "Reference No: " & reference & "<br>"
      Response.Write "Publication: " & publication & "<br>"
      Response.Write "Amount: " & amount & "<br>"
%>
0
CapnJackSparrowCommented:
zamorin,

You don't even need hidden variables. Why don't you do it in a simpler way as follows:

View http://www30.brinkster.com/sslabs/x2/asp/zamorin/page1.asp >>> I assume this is what you want.

<!-- Page 1.asp Starts -->

<form method="post" action="page2.asp">
<input type="radio" name="radio1" value="375 , Playstation , PS001" checked>
PS001 - Playstation : <b>$375.00</b>
<br>
<input type="radio" name="radio1" value="285 , Nokia 7210 , NKJ01">
NKJ01 - Nokia 7210 : <b>$285.00</b>
<br>
<input type="radio" name="radio1" value="123 , N-Gage , NG001">
NG001 - N-Gage : <b>$123.00</b>
<br> <br>
<input type="submit" value="Submit">

</form>

<!-- Page 1.asp Ends -->

<!-- Page 2.asp Starts -->

<% Dim arrProduct
   arrProduct = Split (Request.Form ("radio1") , ",") %>

   <p>
     Product name : <%= arrProduct (1) %> <br>
     Product reference : <%= arrProduct (2) %> <br>
     Amount : <%= arrProduct (0) %>

<!-- Page 2.asp Ends -->

Hope this helps ...

Cheerrs,

ssLabs aka Capn Sparrow, the Black Pearl.
0
zamorinAuthor Commented:
VincentPuglia,

where do I put the function?

ourselves,
I tried your code, but it does not work.

poopall,

I'm a bit confused with your code.

YZlat,

That's the same code I'm using now, where I can't get 1 value but 2.

CapnJackSparrow,

I need to preserve the intergrity of the fields: reference, item and amount, with your code I can't get that to the next page as such.
0
VincentPugliaCommented:
Hi,

put it between
<head>
<script language='javascript' type='text/javascript'>
function doit(formObj)
{
  for (i = 0; i < formObj.length;i++)
  {
      el = formObj.elements[i]
      if (el.name == 'amount' &&  el.checked)
      {
         formObj.hidden1.value = (0 == i) ? 'CSPManual' : "CSPDeluxeManual";
         formObj.hidden2.value = (0 == i) ?  ' P12001' : 'P12002'
         break;
      }
  }
}

</script>
</head>
<body>
<form name='a' >
<table border="1"><tr><td>
<INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3" onclick='doit(document.a)'>
.......etc.....

substitute your form name for 'a' both in the form tag and the function call

Vinny
0
zamorinAuthor Commented:
Hi,

substitute your form name for 'a' both in the form tag and the function call

What do you mean by that?
Now when you click, an error message: "Hidden1 is null or not an object" will appear and both the values are carried to the next page.

Also will this work if I have multiple forms on the same page?

thanks.
0
VincentPugliaCommented:
Sorry,

re 'a' & your 'hidden1' error:

 What I meant was: make sure your form and field names are properly referenced. So, what do I do?  provide you with the wrong names :(

this:

 formObj.hidden1.value = (0 == i) ? 'CSPManual' : "CSPDeluxeManual";
 formObj.hidden2.value = (0 == i) ?  ' P12001' : 'P12002'

should be:

 formObj.item.value = (0 == i) ? 'CSPManual' : "CSPDeluxeManual";
 formObj.reference.value = (0 == i) ?  ' P12001' : 'P12002'

Vinny
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zamorinAuthor Commented:
Vinny,
thank you

I'm home right  now, I'll try it at office tommorow
0
poopallCommented:
My example is basically as follows:

You will transfer tothe next page  one varaiable which will consist of a delimited type string
You can put as many values in this one value by seperating each value with a ":", on the next page you use a function called split() which will break the one value into an array which you can use how you like.

Another option is to have a <form> </form> tag around each radio button option, that will limit which hidden variables are passed to the next page, when the radio button is clicked or selected. Maybe leave out the javascript part.





0
zamorinAuthor Commented:
It still does not work, both the values are being passed to the next page, am I doing anything wrong?

My code now is as follows:

<script language='javascript' type='text/javascript'>
function doit(formObj)
{
  for (i = 0; i < formObj.length;i++)
  {
      el = formObj.elements[i]
      if (el.name == 'amount' &&  el.checked)
      {
         
       formObj.item.value = (0 == i) ? 'CSPManual' : "CSPDeluxeManual";
       formObj.reference.value = (0 == i) ?  ' P12001' : 'P12002'
         break;
      }
  }
}

</script>

---------------------------------------------------------
<FORM name="a" method="post" action="e-payment/publication_csp2.asp">
----------------------------------------------------------

<INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3" onclick='doit(document.a)'>
----------------------------------------------------------

<input type="hidden" value="CSPManual" name="item" id="Hidden1">
<input type="hidden" value="P12001" name="reference" id="Hidden2">
<INPUT type="radio" value="375" name="amount">


<input type="hidden" value="CSPDeluxeManual" name="item" id="Hidden1">
<input type="hidden" value="P12002" name="reference" id="Hidden2">
<INPUT type="radio" value="600" name="amount">


0
zamorinAuthor Commented:
poopall,

But I after the split, I don' t know how to display it out with the original field names ie: Item, reference, amount etc.

0
poopallCommented:
Try this put a form tag around each option

<FORM name="a" method="post" action="e-payment/publication_csp2.asp">
<INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3" >
<input type="hidden" value="CSPManual" name="item" id="Hidden1">
<input type="hidden" value="P12001" name="reference" id="Hidden2">
<INPUT type="radio" value="375" name="amount">
</form>

<FORM name="a" method="post" action="e-payment/publication_csp2.asp">
<INPUT id="Button5" type="image" src="e-payment/images/icon_buy_now.gif" value="Submit" name="button3" >
<input type="hidden" value="CSPDeluxeManual" name="item" id="Hidden1">
<input type="hidden" value="P12002" name="reference" id="Hidden2">
<INPUT type="radio" value="600" name="amount">
</form>

0
poopallCommented:
Looking at you next query it appears that the Split command is working for you, if this is the case why dont we close this query and aware the points ?
0
VincentPugliaCommented:
Hi
   Your form should not have 4 hidden fields. it should only have 2.  


<input type="hidden"  name="item" id="Hidden1">
<input type="hidden"  name="reference" id="Hidden2">

Vinny



0
zamorinAuthor Commented:
Even with 2 hidden fields, It still does not work, both the values are being passed to the next page.
0
zamorinAuthor Commented:
sorry, its working now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.