This is in file: DrinkOrder.asp
<form action="DrinkResult.asp" method="post">
Drink:
<select name="drink">
<option>Coffee</option>
<option>Tea</option>
<option>Hot Chocolate</option>
</select>
<p/>
Sugar:
<input type="radio" name="sugar" value="1"> 1
<input type="radio" name="sugar" value="2"> 2
<input type="radio" name="sugar" value="3"> 3
<p/>
Milk: <input type="checkbox" name="milk">
<p/>
<input type="submit" value="Submit Order"><input type="reset" value="Reset">
</form>
This is in file: DrinkResult.asp
<%#language="Javascript"%>
<%
function milkOn(form){
var with = "";
if(form == "1") { with = "With milk"; }
else { with = "No milk"; }
return with;
}
%>
<%=("<table border=\"1\">")%>
<%=("<tr><th><i>Drink:</i></th>" + "<td> " + (Request.Form("drink")) + "</td>")%>
<%=("<tr><th><i>Sugar:</i></th>" + "<td> " + (Request.Form("sugar")) + "</td>")%>
<%=("<tr><th><i>Milk:</i></th>" + "<td>" + (milkOn(Request.Form("milk"))) + "</td>")%>
<%=("</table>")%>
After submitting form from DrinkOrder.asp to DrinkResult.asp, I received an error which clearly I don't know how to fix it.
After a few modification I made to detect the error location, I'm pretty sure it is located at milkOn(Request.Form("milk")) in file DrinkResult.asp because when I remove the statement, the result shows up.
What's wrong with my code here?
change
if(form == "1")
to
if(form == "on")
otherwise the code seems to test fine for me.
Related
I am trying to add the value of selected checkbox to anchor tag parameter "product-code" and "product-quantity". For example if someone click the first checkbox the product code parameter will be something like product-code="90;1" and product-quantity="1;1". And if someone also check the second checkbox the product code parameter will be like product-code="90;1;2" and product-quantity="1;1;1". Same for the third parameter. Can someone help me with this how I can get this done with the help of jquery?
<input type="checkbox" name="Apple" value="1">
<input type="checkbox" name="Banana" value="2">
<input type="checkbox" name="Orange" value="3">
Order Now!
This solution will work for you.
jQuery(document).ready(function($){
$('input[type=checkbox]').on('change',function(){
let newProductCode = defaultProductCode = $('.avangate_button').attr('product-code').split(';')[0];
let newProductQty = defaultProductQty = $('.avangate_button').attr('product-quantity').split(';')[0];
$('input[type=checkbox]').each(function( index ) {
if($(this).is(':checked')){
newProductQty = newProductQty + ";" + 1;
newProductCode = newProductCode + ";" + $(this).val();
}
});
$('.avangate_button').attr('product-code',newProductCode);
$('.avangate_button').attr('product-quantity',newProductQty);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" name="Apple" value="1">
<input type="checkbox" name="Banana" value="2">
<input type="checkbox" name="Orange" value="3">
Order Now!
its simple you just create two variables e.g productCode & productQuantity and place it anchor tag . Create a function to set upper variables value and execute this function on "onChange" event of checkbox .
here is the code :
<input type="checkbox" name="Apple" value="1">
<input type="checkbox" name="Banana" value="2">
<input type="checkbox" name="Orange" value="3">
<a href="#buy" class="avangate_button btn btn-primary" product-code="90"
product-
quantity="1">Order Now!</a>
var productCode = "90";
var productQuantity = "1";
$("input[type=checkbox]").change(function(val){
productCode = productCode + ";" + val;
productQuantity = productQuantity + ";" + val;
});
If you really want to work with the attribute product-code then the following snippet should do the trick:
const a=document.querySelector("a");
const cbs=[...document.querySelectorAll("input[type=checkbox]")];
cbs.forEach(cb=>cb.addEventListener("click",ev=>{
a.setAttribute("product-code",[90,...cbs.filter(c=>c.checked).map(c=>c.value)].join(";"));
console.log(a);
}));
<input type="checkbox" name="Apple" value="1">
<input type="checkbox" name="Banana" value="2">
<input type="checkbox" name="Orange" value="3">
<a href="#buy" class="avangate_button btn btn-primary" product-code="90"
product-
quantity="1">Order Now!</a>
Please note:
According to the MDM web docs the <a> element does not actually support an attribute product-code. You should therefore rather use something like data-product-code instead.
I have a form that offers a user a choice of whether they would like to receive Email updates. How do I go about making sure that the Email is only 'required' (HTML5 Validation) if the checkbox to receive Email updates is checked.
Here is the form:
<form>
<fieldset>
<legend><b>Details</b></legend>
<label>First Name </label><input id = "fname" type="text" autofocus="" placeholder="Enter first name" name = "fname"><br><br>
<label>Last Name </label><input type="text" placeholder="Enter last name"><br><br>
<label>Email </label><input type="email" placeholder="Enter valid email"> <button onclick="myFunction()">Help</button><br><br>
</fieldset>
<fieldset>
<legend><b>Rating</b></legend>
<label>Website Rating:</label>
<input type="radio" name="Rating" value="1">* (1 Star)
<input type="radio" name="Rating" value="2">* * (2 Star)
<input type="radio" name="Rating" value="3">* * * (3 Star)
<input type="radio" name="Rating" value="4">* * * * (4 Star)
<input type="radio" name="Rating" value="5">* * * * * (5 Star)<br>
</fieldset>
<fieldset>
<legend><b>Comments</b></legend>
<label>Additional Comments:</label>
<textarea id = "feedback1" name="feedback1" rows="2" cols="60"></textarea><br>
</fieldset>
<fieldset>
<legend><b>Updates</b></legend>
Do you want to receive updates via Email?<br>
<input type="checkbox" name="updateYes" value="Yes">Yes
<input type="checkbox" name="update" value="No" checked>No<br>
</fieldset>
<br>
<input type="reset" value="Reset">
<button onclick="myFunction2()" type = "submit">Submit</button>
</form>
<script>
function myFunction() {
alert("Please enter a valid Email adress into the 'Email' field");
}
function myFunction2() {
var checkedRadioButton, inputs, rating;
inputs = document.getElementsByName("Rating");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) {
checkedRadioButton = inputs[i];
break;
}
}
if (checkedRadioButton) {
rating = ("You have rated the website " + checkedRadioButton.value + " Star")
} else {
rating = ("Not Rated")
}
alert("Thank you for your feedback " + document.getElementById('fname').value + "\n" + rating + "\n" + "Your comment was " + document.getElementById('feedback1').value);
}
</script>
I have a standard HTML form, and the button is not working. I know it is directing to the correct page, and as far as I can see everything looks perfect.
It lets me click the button, but then nothing happens, it doesn't direct me to the send.php page or anything.
<form method="post" action="http://www.URL.net/send.php">
<p>
<label for="name">Name <span class="required">*</span></label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">Email <span class="required">*</span></label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="subject">Subject</label>
<input type="text" name="subject" id="subject">
</p>
<p>
<label for="subject">Message <span class="required">*</span></label>
<textarea name="message" id="message" cols="45" rows="10"></textarea>
</p>
<div class="fBtn">
<button type="submit" name="submit" id="submit" class="regButton"><i class="icon-paper-plane"></i>Send Message</button>
</div>
</form>
Also, I have tried using <input type="submit" name="submit" id="submit" class="regButton" value="Send Message" /> as well, but it also isn't working for some odd reason.
Tested in Chrome and IE11.
EDIT Here is the JS for form vaildation:
$('#submit').click(function(){
$('input#name').removeClass("errorForm");
$('textarea#message').removeClass("errorForm");
$('input#email').removeClass("errorForm");
var error = false;
var name = $('input#name').val();
if(name == "" || name == " ") {
error = true;
$('input#name').addClass("errorForm");
}
var msg = $('textarea#message').val();
if(msg == "" || msg == " ") {
error = true;
$('textarea#message').addClass("errorForm");
}
var email_compare = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
var email = $('input#email').val();
if (email == "" || email == " ") {
$('input#email').addClass("errorForm");
error = true;
}else if (!email_compare.test(email)) {
$('input#email').addClass("errorForm");
error = true;
}
if(error == true) {
return false;
}
var data_string = $('.contactForm form').serialize();
$.ajax({
type: "POST",
url: $('.contactForm form').attr('action'),
data: data_string,
success: function(message) {
if(message == 'SENDING'){
$('#success').fadeIn('slow');
}
else{
$('#error').fadeIn('slow');
}
}
});
return false;
});
You appear to have some JavaScript that automatically submits every form using AJAX. Since you’re on the domain trishajohnson.net, the same-origin policy prevents JavaScript from opening requests to a (slightly) different domain – www.trishajohnson.net.
There’s an easy fix, though – just use the path part. It’s cleaner anyway.
<form method="POST" action="/tj/send.php">
I have used HTTPClient to connect to a website and I can successfully access required data from the website using jsoup.
I have the following code from which I need to extract the submit button info.
<form method="POST" action="test.jsp" >
<font size="2">
<input type="hidden" name="num" id="num" value=123 >
<input type="hidden" name="iec" id="iec" value=456 >
<input type="submit" onclick=" return check();" value="Print" name="B1">
</font>
</form>
How can I access the value and name of the submit button?
You can access those values using the attr(String attribute) method of Element. For example:
String html = "<form method=\"POST\" action=\"test.jsp\" >"
+ "<font size=\"2\">"
+ "<input type=\"hidden\" name=\"num\" id=\"num\" value=123 >"
+ "<input type=\"hidden\" name=\"iec\" id=\"iec\" value=456 > "
+ "<input type=\"submit\" onclick=\" return check();\" value=\"Print\" name=\"B1\">"
+ "</font>"
+ "</form>";
Document doc = Jsoup.parse(html);
Element bttn = doc.select("input[type=submit]").first();
String value = bttn.attr("value"); // will be Print
String name = bttn.attr("name"); // will be B1
I have a client selling a t shirt. She wants a potential buyer to be able to choose size and color with a quantity option for each.
I have found some code that tallies the order total, but does not have the quantity option.
I have attached the code below. Can anyone steer me in the right direction on what to do with this? I am fairly new to customizing for PayPal, but I am a web designer so I am no beginner in figuring things out. I have also attached a screen shot of the customer's form she sent via email to show what she wants it to look like.
Any help would be greatly appreciated. Thanks.
alt text http://www.inauguraldayt-shirts.com/shirt.jpg
<!-- Start of Script -->
<SCRIPT type=text/javascript>
<!--
function Dollar (val) { // force to valid dollar amount
var str,pos,rnd=0;
if (val < .995) rnd = 1; // for old Netscape browsers
str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape
pos = str.indexOf (".");
if (pos > 0) str = str.substring (rnd, pos + 3);
return str;
}function ReadForm (obj1, tst) { // process radio and checkbox
var i,j,amt=0,des="",obj,pos,val,tok,tag,
op1a="",op1b="",op2a="",op2b="",itmn="";
var ary = new Array ();
if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount
if (obj1.basedes) des = obj1.basedes.value; // base description
if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
if (obj1.baseos0) op1b = obj1.baseos0.value;
if (obj1.baseon1) op2a = obj1.baseon1.value;
if (obj1.baseos1) op2b = obj1.baseos1.value;
if (obj1.baseitn) itmn = obj1.baseitn.value;
for (i=0; i<obj1.length; i++) { // run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == "checkbox" || // checkboxes
obj.type == "radio") { // and radios
if (obj.checked) { // did user check it?
val = obj.value; // the value of the selection
ary = val.split (" "); // break apart
for (j=0; j<ary.length; j++) { // look at all items
// first we do single character tokens...
if (ary[j].length < 2) continue;
tok = ary[j].substring (0,1); // first character
val = ary[j].substring (1); // get data
if (tok == "#") amt = val * 1.0;
if (tok == "+") amt = amt + val*1.0;
if (tok == "%") amt = amt + (amt * val/100.0);
if (tok == "#") { // record item number
if (obj1.item_number) obj1.item_number.value = val;
ary[j] = ""; // zap this array element
}
// Now we do 3-character tokens...
if (ary[j].length < 4) continue;
tok = ary[j].substring (0,3); // first 3 chars
val = ary[j].substring (3); // get data
if (tok == "s1=") { // value for shipping
if (obj1.shipping) obj1.shipping.value = val;
ary[j] = ""; // clear it out
}
if (tok == "s2=") { // value for shipping2
if (obj1.shipping2) obj1.shipping2.value = val;
ary[j] = ""; // clear it out
}
}
val = ary.join (" "); // rebuild val with what's left tag = obj.name.substring (obj.name.length-2); // get flag
if (tag == "1a") op1a = op1a + " " + val;
else if (tag == "1b") op1b = op1b + " " + val;
else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
else if (tag == "3i") itmn = itmn + " " + val;
else if (des.length == 0) des = val;
else des = des + ", " + val;
}
}
}
// Now summarize stuff we just processed, above
if (op1a.length > 0) obj1.on0.value = op1a;
if (op1b.length > 0) obj1.os0.value = op1b;
if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
if (itmn.length > 0) obj1.item_number.value = itmn;
obj1.item_name.value = des;
obj1.amount.value = Dollar (amt);
if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}
//-->
</SCRIPT>
<!-- End of Script -->
<div id="button">
<!-- Another method for the View Cart Form - add this code anywhere within the web page -->
<!-- This is the FORM to view the cart contents -->
<!-- Note: target="paypal" was replaced with the variable target="_self" -->
<!-- Note: shopping_url also added to code -->
<!-- These two changes allow better functionality with IE and Firefox -->
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="viewcart" name="viewcart">
<p>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<input type="hidden" name="business" value="you#you.com">
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/your_page.html">
</p>
</form>
<!-- End of the viewcart FORM -->
<!-- Start of Form -->
<!-- Note: target="paypal" was replaced with the variable target="_self" -->
<!-- Note: shopping_url also added to code -->
<!-- These two changes allow better functionality with IE and Firefox -->
<FORM onsubmit="this.target='_self';
return ReadForm(this, true);" action=https://www.paypal.com/cgi-bin/webscr method=post>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="you#you.com">
<input type="hidden" name="item_name" value="">
<input type="hidden" name="amount" value="">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-ShopCartBF">
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/your_page.html">
<input type="hidden" name="cancel_return" value="http://www.yourwebsite.com/Cancel.html">
<input type="hidden" name="return" value="http://www.yourwebsite.com/Success.html">
<input type="hidden" value="0.00" name="baseamt">
<input type="hidden" value="Inaugural Day T-Shirt - #17.99" name="basedes">
Inaugural Day T-Shirt - $17.99
<br><br>
Colors
<br><br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="White +17.99"> White - $17.99
Select Quantity:
<select name="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="Blue +17.99"> Blue - $17.99
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="Black +17.99"> Black - $17.99
<br><br><br>
Sizes
<br><br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="Small +17.99"> Small - $17.99
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="Medium +17.99"> Medium - $17.99
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="Large +17.99"> Large - $17.99
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="XL +19.99"> XL - $19.99
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="XXL +19.99"> XXL - $19.99
<br>
<input onclick="ReadForm (this.form, false);" type=checkbox value="XXXL +19.99"> XXXL - $19.99
<br><br><br>
<input onclick="this.form.reset ();" type=button value="Reset Form"> Item Total >
<input class=nbor size=6 value=$0.00 name=tot>
<br><br>
<input type=image alt="cart add" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" name=submit>
<br><br>
<input onclick="document.forms.viewcart.target = '_self';
document.forms.viewcart.submit ();
return false;" type=image alt="cart view" src="https://www.paypal.com/en_US/i/btn/btn_viewcart_LG.gif"">
</FORM>
<!-- End of Form -->
For a basic HTML page, use PayPal's own button wizard. Just go to Merchant Services -> Add to Cart button. It will allow you to customize the button to specify different sizes via a drop down and even select a quantity when the item is added to the cart. You can also add a "view cart" button as well and everything is taken care of for you. I used this on a recent site.
Granted adding items and viewing the cart takes the user to a PayPal page, but unless they're looking for a fully integrated site, this option is fast, easy, and robust. Plus PayPal does a good job at tracking where the order page is coming from so the user can easily navigate back.