Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

simple form

Hello,

I have a question about a simple form on a page called pizza.asp.

<form name="formPizza" action="pizza.asp">
  <input type="checkbox" value="Pepperoni">Pepperoni<br>
  <input type="checkbox" value="Onion">Onion<br>
  <input type="checkbox" value="Mushroom">Mushroom<br>
  <input type="submit" name="submit" value="Submit">
</form>

You have selected the following items for your pizza:

How do I get the values for the checkboxes checked to display below the form?  Do I use post or get for the method?  The user should be able to clear the previously checked boxes too and select new ones.  Clicking on the submit button will then display their new results.

Thanks!
0
tudovich
Asked:
tudovich
  • 6
  • 5
  • 2
  • +5
1 Solution
 
paStiSSetCommented:
you have installed PHP and MySQL on your server? or it must be only in ASP? i can help you with PHP
0
 
tudovichAuthor Commented:
it must be in ASP.
0
 
rstorey2079Commented:
You can choose whether you want to use get or post.  Just specify it in your form.  Post is usually the preferred method.

You also need to name your checkboxes.  You cannot use them after submitting the form if they do not have names.

<form method="post" name="formPizza" action="pizza.asp">
 <input type="checkbox" name="topping1" value="Pepperoni">Pepperoni<br>
  <input type="checkbox" name="topping2" value="Onion">Onion<br>
  <input type="checkbox" name="topping3" value="Mushroom">Mushroom<br>
  <input type="submit" name="submit" value="Submit">
</form>

Now, when you hit the submit button, the name and value pairs for the checkboxes that are checked will be sent to pizza.asp.  If the checkbox is unchecked when the form is submitted, it is not passed to pizza.asp.

That's as far as I can help you...I don't know anything about ASP.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mattjp88Commented:
well you have a few problems with your form.  first of all, the check boxes dont have names, which makes it impossible to get the values for.  this is a working form:

<form name="formPizza" action="pizza.asp">
  <input type="checkbox" name="Pepperoni" value="yes">Pepperoni<br>
  <input type="checkbox" name="Onion" value="yes">Onion<br>
  <input type="checkbox" name="Mushroom" value="yes">Mushroom<br>
  <input type="submit" name="submit" value="Submit">
</form>

and about post or get, you would use GET with the way you have it, if you want to use post, change the <form> tag to this:

<form name="formPizza" method="POST" action="pizza.asp">

and to be very picky, you need to actually modify the existing code to make the GET moethod to work with coreect santax.  by default, the method is GET, but to be sure, change your form tag to this:

<form name="formPizza" method="GET" action="pizza.asp">

-Matt
0
 
superslamwichCommented:
Although I don't know anything about asp, you can use simple HTML to get the variables that are passed:

<form name="formPizza" action="pizza.asp">
 <input type="checkbox" name="Pepperoni" value="yes">Pepperoni<br>
 <input type="checkbox" name="Onion" value="yes">Onion<br>
 <input type="checkbox" name="Mushroom" value="yes">Mushroom<br>
 <input type="submit" name="submit" value="Submit">
</form>

<script type='text/javascript'>
<!--
  args = document.location.search
  writein = "<b>Selected Toppings:</b><p>"
  if(args != "")  {
    info = args.substr(args.indexOf('?')+1)
    vars = info.split('&')
    q=false
    for(i=0;i<vars.length;i++)  {
      if(vars[i].split('=')[0] == "Pepperoni")  {
        writein += "Pepperoni<br>"
        document.formPizza.Pepperoni.checked=true
        q=true
      }
      if(vars[i].split('=')[0] == "Onion")  {
        writein += "Onion<br>"
        document.formPizza.Onion.checked=true
        q=true
      }
      if(vars[i].split('=')[0] == "Mushroom")  {
        writein += "Mushroom<br>"
        document.formPizza.Mushroom.checked=true
        q=true
      }
    }
    if(!q)  writein += "None"
    document.write(writein)
  }
//-->
</script>

{Slam}
0
 
HeadAcheMikeCommented:
I know you said you want it in ASP however i have done it in PHP, it should be fairly straight forward to convert. Anyway, heres the code (note. filename extension must be .php):

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="formPizza" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
  <input type="checkbox" name="Pepperoni" value="Pepperoni">Pepperoni<br>
  <input type="checkbox" name="Onion" value="Onion">Onion<br>
  <input type="checkbox" name="Mushroom" value="Mushroom">Mushroom<br>
  <input type="submit" name="submit" value="Submit">
</form>

<?php
if(isset($_POST['submit'])) print "You Selected: <p>";
if(isset($_POST['Pepperoni'])) print $_POST['Pepperoni']."<br>";
if(isset($_POST['Onion'])) print $_POST['Onion']."<br>";
if(isset($_POST['Mushroom'])) print $_POST['Mushroom'];
?>

</body>
</html>
0
 
fozyletCommented:
Here is the ASP for u... save the part below as pizza.asp

<%
Dim Pepperoni, Onion, Mushroom
Pepperoni = Request("Pepperoni")
Onion = Request("Onion")
Mushroom = Request("Mushroom")

If Pepperoni<>"" Then Response.Write "You selected Pepperoni"
'... similarly for onion
'... and mushroom

'And the html follows... (note the method attribute in form tag and the name attribute in checkbox)
%>

<form name="formPizza" action="pizza.asp" method="post">
  <input type="checkbox" name="Pepperoni" value="Pepperoni">Pepperoni<br>
  <input type="checkbox" name="Onion" value="Onion">Onion<br>
  <input type="checkbox" name="Mushroom" value="Mushroom">Mushroom<br>
  <input type="submit" name="submit" value="Submit">
</form>
0
 
HeadAcheMikeCommented:
seems to be a lot better in php if you ask me, just my personal opinion take note
0
 
fozyletCommented:
tudovich... are you trying out any of the solutions?

Also, please look into your previous questions.

Questions Asked  12
Questions Open  9
Questions Graded:  2
Questions Deleted:  1
0
 
jaysolomonCommented:
Here is a asp solution

<%
      pizza = request.form("pizza")
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="formPizza" action="" method="post">
 <input type="checkbox" name="pizza" value="Pepperoni">Pepperoni<br>
 <input type="checkbox" name="pizza" value="Onion">Onion<br>
  <input type="checkbox" name="pizza" value="Mushroom">Mushroom<br>
  <input type="submit" name="submit" value="Submit">
</form>
<%
If pizza<>"" then
      response.write("<hr /><p>You like: <b>" & request.form("pizza") &"</b></p>")
end If%>
</body>
</html>


0
 
mattjp88Commented:
i got a question jay, since all the checkboxes are the same name, then wont only 1 value get passed?  so if i check Pepperioni and Onion, from my past experiences, only Onion wil get passed.

-Matt
0
 
jaysolomonCommented:
No matt this is the output

You like: Pepperoni, Onion, Mushroom
0
 
jaysolomonCommented:
Atleast thats what i got on my IE6 and NS7
0
 
fozyletCommented:
What jay says is right, if more than one element has the same name then a CSV of all values in that name will come with the request, for that element name. Am not really sure if ALL browsers will handle it this way.

The disadvantage is that we need to do further processing (like a split) to take individual values out of it.

0
 
jaysolomonCommented:
fozy i will have to let you do the split ;)

i am a javscript'r learning asp
0
 
fozyletCommented:
The author seems least interested in any of the post jay...
but here you are if you are interested

myArray = Split( Request("pizza"), "," )

Now myArray(0) will have "Pepperoni" and so on...

For iCnt = 0 To UBound(myArray)
  Response.Write myArray(iCnt) & "<br>"
Next
0
 
jaysolomonCommented:
Thanks fozy

what about this


<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="formPizza" action="" method="post">
...

....

</form>
<%
         for each pizza in request.form("pizza")
%>
     <p>You Choose: <b> <%= pizza%></b></p>
<%
        next
%>
..
..

.

.

I have not tested this, just curious since i am at home i do not have time to tested it.
0
 
fozyletCommented:
Don't think that will work since request.form("pizza") itself is an item and not an object.

what you are trying to do is enumerate the items in an object, but you are trying that on an item.

guess the one below will work though.

for each pizza in request.form
   Response.Write "You selected " & request.form(pizza) & "<br>"
next

but for this to work the checkboxes should have different names and submit button should not have a name
0
 
jaysolomonCommented:
ok

i just tested my other solution

and this is the out put i got when i checked all 3 boxes
You chose: Pepperoni

You chose: Onion

You chose: Mushroom


and the output for one box
You chose: Pepperoni

Fozy thanks for your help, i am trying to learn asp as fast as i learned JS

I don't guess the questioneer really wanted an asp solution afterall
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 5
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now