Solved

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

Posted on 2003-10-28
22
241 Views
Last Modified: 2010-04-06
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>
0
Comment
Question by:zamorin
  • 9
  • 5
  • 5
  • +3
22 Comments
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9638988
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
 
LVL 5

Author Comment

by:zamorin
ID: 9639134
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
 
LVL 2

Expert Comment

by:poopall
ID: 9639829
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
 
LVL 5

Author Comment

by:zamorin
ID: 9639915
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
 
LVL 2

Expert Comment

by:poopall
ID: 9640657
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9641602
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
 
LVL 35

Expert Comment

by:YZlat
ID: 9641703
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
 

Expert Comment

by:ourselves
ID: 9646800
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
 
LVL 1

Expert Comment

by:CapnJackSparrow
ID: 9648132
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
 
LVL 5

Author Comment

by:zamorin
ID: 9655134
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9655208
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 5

Author Comment

by:zamorin
ID: 9655289
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
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 50 total points
ID: 9657143
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
 
LVL 5

Author Comment

by:zamorin
ID: 9658905
Vinny,
thank you

I'm home right  now, I'll try it at office tommorow
0
 
LVL 2

Expert Comment

by:poopall
ID: 9661276
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
 
LVL 5

Author Comment

by:zamorin
ID: 9668116
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
 
LVL 5

Author Comment

by:zamorin
ID: 9668160
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
 
LVL 2

Assisted Solution

by:poopall
poopall earned 20 total points
ID: 9669289
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
 
LVL 2

Expert Comment

by:poopall
ID: 9700080
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9701037
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
 
LVL 5

Author Comment

by:zamorin
ID: 9776917
Even with 2 hidden fields, It still does not work, both the values are being passed to the next page.
0
 
LVL 5

Author Comment

by:zamorin
ID: 9776969
sorry, its working now.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now