tudovich
asked on
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">Pepperon i<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!
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">Pepperon
<input type="checkbox" value="Onion">Onion<br>
<input type="checkbox" value="Mushroom">Mushroom<
<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!
you have installed PHP and MySQL on your server? or it must be only in ASP? i can help you with PHP
ASKER
it must be in ASP.
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">Pepperon i<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.
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">Pepperon
<input type="checkbox" name="topping2" value="Onion">Onion<br>
<input type="checkbox" name="topping3" value="Mushroom">Mushroom<
<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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Peppero ni.checked =true
q=true
}
if(vars[i].split('=')[0] == "Onion") {
writein += "Onion<br>"
document.formPizza.Onion.c hecked=tru e
q=true
}
if(vars[i].split('=')[0] == "Mushroom") {
writein += "Mushroom<br>"
document.formPizza.Mushroo m.checked= true
q=true
}
}
if(!q) writein += "None"
document.write(writein)
}
//-->
</script>
{Slam}
<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('
vars = info.split('&')
q=false
for(i=0;i<vars.length;i++)
if(vars[i].split('=')[0] == "Pepperoni") {
writein += "Pepperoni<br>"
document.formPizza.Peppero
q=true
}
if(vars[i].split('=')[0] == "Onion") {
writein += "Onion<br>"
document.formPizza.Onion.c
q=true
}
if(vars[i].split('=')[0] == "Mushroom") {
writein += "Mushroom<br>"
document.formPizza.Mushroo
q=true
}
}
if(!q) writein += "None"
document.write(writein)
}
//-->
</script>
{Slam}
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">Pepperon i<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>
<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">Pepperon
<input type="checkbox" name="Onion" value="Onion">Onion<br>
<input type="checkbox" name="Mushroom" value="Mushroom">Mushroom<
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit'])
if(isset($_POST['Pepperoni
if(isset($_POST['Onion']))
if(isset($_POST['Mushroom'
?>
</body>
</html>
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">Pepperon i<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>
<%
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">Pepperon
<input type="checkbox" name="Onion" value="Onion">Onion<br>
<input type="checkbox" name="Mushroom" value="Mushroom">Mushroom<
<input type="submit" name="submit" value="Submit">
</form>
seems to be a lot better in php if you ask me, just my personal opinion take note
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
Also, please look into your previous questions.
Questions Asked 12
Questions Open 9
Questions Graded: 2
Questions Deleted: 1
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">Pepperon i<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>
<%
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">Pepperon
<input type="checkbox" name="pizza" value="Onion">Onion<br>
<input type="checkbox" name="pizza" value="Mushroom">Mushroom<
<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>
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
-Matt
No matt this is the output
You like: Pepperoni, Onion, Mushroom
You like: Pepperoni, Onion, Mushroom
Atleast thats what i got on my IE6 and NS7
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.
The disadvantage is that we need to do further processing (like a split) to take individual values out of it.
fozy i will have to let you do the split ;)
i am a javscript'r learning asp
i am a javscript'r learning asp
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
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
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.
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.
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
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
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
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