I have a paypal checkout form where I need to join together multiple chosen checkbox values (name="cb1") into a single string so it can be submitted as a hidden input (name="os1") value. I'm going round in circles trying to figure this out. I know very little JS! Can somebody help please?
<div id="buyform">
<form target="paypal" id="ppform" name="ppform" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="myPPbusinessid">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="Form Title">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<div><input type="hidden" name="on0" value="Options"><h5>Options</h5></div>
<div>
<select name="os0" id="os0" required>
<option value="Chosen Product">Any quantity £10.00 GBP</option>
</select>
</div>
<input type="hidden" name="on1" value="Colours">
<div>
<input type="checkbox" name="cb1" value="Red" id="os10" class="thecbox"/><label for="os10"></label>
<input type="checkbox" name="cb1" value="Green" id="os11" class="thecbox"/><label for="os11"></label>
<input type="checkbox" name="cb1" value="Orange" id="os12" class="thecbox"/><label for="os12"></label>
<input type="checkbox" name="cb1" value="Purple" id="os13" class="thecbox"/><label for="os13"></label>
<input type="checkbox" name="cb1" value="Yellow" id="os14" class="thecbox"/><label for="os14"></label>
<input type="checkbox" name="cb1" value="Black" id="os15" class="thecbox"/><label for="os15"></label>
<input type="checkbox" name="cb1" value="Blue" id="os16" class="thecbox"/><label for="os16"></label>
<input type="hidden" name="os1" value="EACH, CHECKED, VALUE, HERE">
</div>
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="option_select0" value="Options">
<input type="hidden" name="option_amount0" value="10.00">
<input type="hidden" name="option_index" value="0">
<input type="hidden" name="currency_code" value="GBP">
<input type="submit" border="0" name="submit" id="submit" value="Purchase" class="buynow mb0"></form>
</div>
I seem to have got it working exactly as wanted. Can't help feeling that the JS needs tidying though! Seems long for what I suspect should be a smaller piece of code... like I say: my JS is poor to non-existent!
<script type="text/javascript">
function checkTotal() {
document.ppform.os1.value = '';
if (document.getElementById('os10').checked){
var cb1str = document.ppform.cb1.value;
} else {
var cb1str = '';
}
if (document.getElementById('os11').checked){
var cb2str = document.ppform.cb2.value;
} else {
var cb2str = '';
}
if (document.getElementById('os12').checked){
var cb3str = document.ppform.cb3.value;
} else {
var cb3str = '';
}
if (document.getElementById('os13').checked){
var cb4str = document.ppform.cb4.value;
} else {
var cb4str = '';
}
if (document.getElementById('os14').checked){
var cb5str = document.ppform.cb5.value;
} else {
var cb5str = '';
}
if (document.getElementById('os15').checked){
var cb6str = document.ppform.cb6.value;
} else {
var cb6str = '';
}
if (document.getElementById('os16').checked){
var cb7str = document.ppform.cb7.value;
} else {
var cb7str = '';
}
var sum = cb1str.concat(cb2str).concat(cb3str).concat(cb4str).concat(cb5str).concat(cb6str).concat(cb7str);
document.ppform.os1.value = sum;
}
</script>
<div id="buyform">
<form target="paypal" id="ppform" name="ppform" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="myPPbusinessid">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="Form Title">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<div><input type="hidden" name="on0" value="Options"><h5>Options</h5></div>
<div>
<select name="os0" id="os0" required>
<option value="Chosen Product">Any quantity £10.00 GBP</option>
</select>
</div>
<input type="hidden" name="on1" value="Colours">
<div>
<input type="checkbox" name="cb1" value="Red " id="os10" onchange="checkTotal()" /><label for="os10"></label>
<input type="checkbox" name="cb2" value="Green " id="os11" onchange="checkTotal()" /><label for="os11"></label>
<input type="checkbox" name="cb3" value="Orange " id="os12" onchange="checkTotal()" /><label for="os12"></label>
<input type="checkbox" name="cb4" value="Purple " id="os13" onchange="checkTotal()" /><label for="os13"></label>
<input type="checkbox" name="cb5" value="Yellow " id="os14" onchange="checkTotal()" /><label for="os14"></label>
<input type="checkbox" name="cb6" value="Black " id="os15" onchange="checkTotal()" /><label for="os15"></label>
<input type="checkbox" name="cb7" value="Blue " id="os16" onchange="checkTotal()" /><label for="os16"></label>
<input type="hidden" name="os1" value="">
</div>
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="option_select0" value="Options">
<input type="hidden" name="option_amount0" value="10.00">
<input type="hidden" name="option_index" value="0">
<input type="hidden" name="currency_code" value="GBP">
<input type="submit" border="0" name="submit" id="submit" value="Purchase" class="buynow mb0"></form>
</div>
Related
I'm trying to integrate a payment method called SiamPay on my website but I don't know javascript :(
On SiamPay website they have this instructions:
Copy the following program code to your payment page and
dynamic generate the Amount show below by yourself
<form name="payForm" method="post" action="https://www.siampay.com/b2c2/eng/payment/payForm.jsp">
<input type="submit" name="submit" value="Buy">
<input type="hidden" name="amount" value="Amount">
<input type="hidden" name="merchantId" value="76117579">
<input type="hidden" name="orderRef" value="76117579">
<input type="hidden" name="currCode" value="764" >
<input type="hidden" name="successUrl" value="">
<input type="hidden" name="failUrl" value="">
<input type="hidden" name="cancelUrl" value="">
<input type="hidden" name="remark" value="">
<input type="hidden" name="lang" value="E">
<input type="hidden" name="payMethod" value="ALL">
</form>
Example in jsp:
<%
double amount = qty * unitPrice ;
%>
<form name="payForm" method="post" action="https://www.siampay.com/eng/payment/payForm.jsp">
<input type="submit" name="submit" value="Buy">
<input type="hidden" name="amount" value="<%= amount %>">
<input type="hidden" name="merchantId" value="76117579">
<input type="hidden" name="orderRef" value="76117579">
<input type="hidden" name="currCode" value="764" >
<input type="hidden" name="successUrl" value="">
<input type="hidden" name="failUrl" value="">
<input type="hidden" name="cancelUrl" value="">
<input type="hidden" name="remark" value="">
<input type="hidden" name="lang" value="E">
</form>
I would like to create a field where the user can input an amount to pay in THB (Thai currency) and transport that value to this field:
< input type="hidden" name="amount" value="<%= amount %>">.
I think this is relatively easy but because I never user javascript I'm a little confused.
I appreciate any help.
Thank you so much.
Best Regards,
Alex
There's no need to create an extra input field. You have to change the name=amount input's type to number so that it will become visible to the user. Now the user can enter a number of their choice and click the pay button to submit the payment form.
<form name="payForm" method="post" action="https://www.siampay.com/eng/payment/payForm.jsp">
<input type="submit" name="submit" value="Buy">
<input type="number" name="amount" value="" placeholder="Enter amount in THB ">
<input type="hidden" name="merchantId" value="76117579">
<input type="hidden" name="orderRef" value="76117579">
<input type="hidden" name="currCode" value="764" >
<input type="hidden" name="successUrl" value="">
<input type="hidden" name="failUrl" value="">
<input type="hidden" name="cancelUrl" value="">
<input type="hidden" name="remark" value="">
<input type="hidden" name="lang" value="E">
</form>
To set value to an element, you can use the document.getElementById().value function. Set the amount data into the Amount variable as shown below.
var Amount = 123;
Also, modify the input tag for the amount to include the same id:
<input type="hidden" name="amount" id="amtId" value="Amount">
var Amount = 123;
function setAmountValue() {
document.getElementById('amtId').value = Amount;
}
<form name="payForm" method="post" action="https://www.siampay.com/b2c2/eng/payment/payForm.jsp">
<input type="submit" name="submit" value="Buy" onclick="setAmountValue();">
<input type="hidden" name="amount" id="amtId" value="Amount">
<input type="hidden" name="merchantId" value="76117579">
<input type="hidden" name="orderRef" value="76117579">
<input type="hidden" name="currCode" value="764">
<input type="hidden" name="successUrl" value="">
<input type="hidden" name="failUrl" value="">
<input type="hidden" name="cancelUrl" value="">
<input type="hidden" name="remark" value="">
<input type="hidden" name="lang" value="E">
<input type="hidden" name="payMethod" value="ALL">
</form>
try something like this:
<form name="payForm" method="post" action="https://www.siampay.com/eng/payment
/payForm.jsp">
<input type="submit" name="submit" value="Buy">
<input type="hidden" id="amount" value="<%= amount %>">
<input type="hidden" name="merchantId" value="76117579">
<input type="hidden" name="orderRef" value="76117579">
<input type="hidden" name="currCode" value="764" >
<input type="hidden" name="successUrl" value="">
<input type="hidden" name="failUrl" value="">
<input type="hidden" name="cancelUrl" value="">
<input type="hidden" name="remark" value="">
<input type="hidden" name="lang" value="E">
</form>
<button id='cmdSend'>Click me</button>
<input id='howmuch' type="number" name="amount" value=1000>
And the JS:
document.getElementById("cmdSend").addEventListener("click", myFunction);
function myFunction() {
document.getElementById("cmdSend").innerHTML = "YOU CLICKED ME!";
//Get the value the user typed:
var Value = document.getElementById("howmuch").value;
console.log(Value);
//Set the value into the hidden input, can be done in 2 ways:
document.getElementById("amount").value = Value;
document.getElementById("amount").setAttribute('value',Value);
//Check the value got assigned:
console.log(document.getElementById("amount").value);
}
Fiddle here: https://jsfiddle.net/s2ztkn8L/
I'd like to be able to use a total amount generated using javascriptand displayed on the page in a <span> field later on in an HTML form. The checkbox additions and subtractions work correctly, I have no issue with that. What I have not been able to figure out is how to use that value later on in an HTML field (shown below as the PayPal code).
I have this in the <head> which handles the javascript:
<head>
<script type="text/javascript">
var total = 0.00;
function test(item) {
if (item.checked) {
total += parseFloat(item.value);
} else {
total -= parseFloat(item.value);
}
//alert(total);
document.getElementById('Totalcost').innerHTML = total.toFixed(2);
}
</script>
</head>
The this adds/subtracts if a check box is checked:
<td class="column-3">
<br>
<label class="container">
<input type="checkbox" name="Shoes" value="2.95" onClick="test(this);">Select<span class="checkmark"></span>
</label>
</td>
<td class="column-3">
<br>
<label class="container">
<input type="checkbox" name="Clothes" value="2.95" onClick="test(this);">Select<span class="checkmark"></span>
</label>
</td>
Then I display the total with this:
Total Amount: $<span id="Totalcost">0.00</span>
All of this works correctly and checking/unchecking reflects on the Total Amount shown at the bottom of the page.
What I'd like to do is use the total amount that is show in the HTML below for the PayPal subscription link so that the amount is added into the
line.
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="myemailaddress.com">
<input type="hidden" name="item_name" value="Shows & Clothes">
<input type="hidden" name="item_description" value="Shows & Clothes">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="no_shipping" value="1">
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
<input type="hidden" name="a3" value="TOTAL_AMOUNT">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
</form>
Is it possible to capture the 'totalcost' and have it dynamically added to the "a3" field in the PayPal form (where it says TOTAL_AMOUNT) for when the customer clicks the PayPal button it already has the correct value/amount in the form?
Thank you.
You can use document.getElementsByName. By default you'll get a NodeList. For example:
var a3 = document.getElementsByName("a3")[0];
a3.value = total.toFixed(2);
You can easily update its value.
Something like this:
var total = 0.00;
function test(item) {
if (item.checked) {
total += parseFloat(item.value);
} else {
total -= parseFloat(item.value);
}
document.getElementById("Totalcost").innerHTML = total.toFixed(2);
var a3 = document.getElementsByName("a3")[0];
a3.value = total.toFixed(2);
}
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="myemailaddress.com">
<input type="hidden" name="item_name" value="Shows & Clothes">
<input type="hidden" name="item_description" value="Shows & Clothes">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="no_shipping" value="1">
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
<input type="hidden" name="a3" value="TOTAL_AMOUNT">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
</form>
<table>
<tr>
<td class="column-3">
<br>
<label class="container">
<input type="checkbox" name="Shoes" value="2.95" onClick="test(this);">Select<span class="checkmark"></span>
</label>
</td>
<td class="column-3">
<br>
<label class="container">
<input type="checkbox" name="Clothes" value="2.95" onClick="test(this);">Select<span class="checkmark"></span>
</label>
</td>
</tr>
</table>
<span id="Totalcost">0.00</span>
i want to to take the attendance of students. in the get attendance page i got a list of all the students with 3 radio buttons for each student. i want to check if the attendance of all the students is marked and the submit (either present ,Absent or Leave) cant find out please help. the function i use works only iff present is checked.(sorry but i need only pure javascript code)
<html>
<head>
<title>KUSC | Attendance Management System</title>
<script type="text/javascript" language="javascript">
function check()
{
var rc = document.getElementById("rc").value;
for(var i=1;i<=rc;i++)
{
var x="att"+i;
var y="rid"+i;
if(document.getElementById(""+x).checked==false)
{
document.getElementById(""+y).bgColor="Red";
document.getElementById(""+y).focus();
return false;
}
}
return true;
}
</script>
</head>
<body>
<form name="attspl" method="post" onSubmit="return check();">
<center>
<table width="600" border="1" id="table">
<tr><td colspan = "4" align = "center">
<b><font color = 'red'> Taking Attendance of MCA 1 for   C</font></b></td>
</tr><tr>
<td><b>S No.</b></td>
<td><b>Roll No</b></td>
<td><b>Student Name</b></td>
<td><b>Present Status</b></td></tr>
<tr><td>1</td><td>14045113001</td><td>Nayeem Ahmad Bhat</td><td id=rid1>
<input type="hidden" name="rno1" value="14045113001"/>
<input type="hidden" name="stdname1" value="Nayeem Ahmad Bhat"/>
<input type="radio" id="att1" name="att1" value="P" />Present
<input type="radio" id="att1" name="att1" value="A" />Absent
<input type="radio" id="att1" name="att1" value="L" />Leave
</td></tr><tr><td>2</td><td>14045113002</td><td>Farooq Ahmad Sheikh</td><td id=rid2>
<input type="hidden" name="rno2" value="14045113002"/>
<input type="hidden" name="stdname2" value="Farooq Ahmad Sheikh"/>
<input type="radio" id="att2" name="att2" value="P" />Present
<input type="radio" id="att2" name="att2" value="A" />Absent
<input type="radio" id="att2" name="att2" value="L" />Leave
</td></tr><tr><td>3</td><td>14045113003</td><td>Zubair Ahmad Khan</td><td id=rid3>
<input type="hidden" name="rno3" value="14045113003"/>
<input type="hidden" name="stdname3" value="Zubair Ahmad Khan"/>
<input type="radio" id="att3" name="att3" value="P" />Present
<input type="radio" id="att3" name="att3" value="A" />Absent
<input type="radio" id="att3" name="att3" value="L" />Leave
</td></tr><tr><td>4</td><td>14045113004</td><td>Shahid Nazir</td><td id=rid4>
<input type="hidden" name="rno4" value="14045113004"/>
<input type="hidden" name="stdname4" value="Shahid Nazir"/>
<input type="radio" id="att4" name="att4" value="P" />Present
<input type="radio" id="att4" name="att4" value="A" />Absent
<input type="radio" id="att4" name="att4" value="L" />Leave
</td></tr><tr><td>5</td><td>14045113005</td><td>Faizan Qadri</td><td id=rid5>
<input type="hidden" name="rno5" value="14045113005"/>
<input type="hidden" name="stdname5" value="Faizan Qadri"/>
<input type="radio" id="att5" name="att5" value="P" />Present
<input type="radio" id="att5" name="att5" value="A" />Absent
<input type="radio" id="att5" name="att5" value="L" />Leave
</td></tr><tr><td>6</td><td>14045113006</td><td>Farooq Ahmad Joo</td><td id=rid6>
<input type="hidden" name="rno6" value="14045113006"/>
<input type="hidden" name="stdname6" value="Farooq Ahmad Joo"/>
<input type="radio" id="att6" name="att6" value="P" />Present
<input type="radio" id="att6" name="att6" value="A" />Absent
<input type="radio" id="att6" name="att6" value="L" />Leave
</td></tr><tr><td>7</td><td>14045113007</td><td>Sajad Ahmad</td><td id=rid7>
<input type="hidden" name="rno7" value="14045113007"/>
<input type="hidden" name="stdname7" value="Sajad Ahmad"/>
<input type="radio" id="att7" name="att7" value="P" />Present
<input type="radio" id="att7" name="att7" value="A" />Absent
<input type="radio" id="att7" name="att7" value="L" />Leave
</td></tr><tr><td>8</td><td>14045113008</td><td>Shoaib Kirmani</td><td id=rid8>
<input type="hidden" name="rno8" value="14045113008"/>
<input type="hidden" name="stdname8" value="Shoaib Kirmani"/>
<input type="radio" id="att8" name="att8" value="P" />Present
<input type="radio" id="att8" name="att8" value="A" />Absent
<input type="radio" id="att8" name="att8" value="L" />Leave
</td></tr><tr><td>9</td><td>14045113009</td><td>Bilal Ahmad Hajam</td><td id=rid9>
<input type="hidden" name="rno9" value="14045113009"/>
<input type="hidden" name="stdname9" value="Bilal Ahmad Hajam"/>
<input type="radio" id="att9" name="att9" value="P" />Present
<input type="radio" id="att9" name="att9" value="A" />Absent
<input type="radio" id="att9" name="att9" value="L" />Leave
</td></tr><tr><td>10</td><td>14045113010</td><td>Danish Nabi</td><td id=rid10>
<input type="hidden" name="rno10" value="14045113010"/>
<input type="hidden" name="stdname10" value="Danish Nabi"/>
<input type="radio" id="att10" name="att10" value="P" />Present
<input type="radio" id="att10" name="att10" value="A" />Absent
<input type="radio" id="att10" name="att10" value="L" />Leave
</td></tr><tr><td>11</td><td>14045113011</td><td>Manzoor Ahmad Mir</td><td id=rid11>
<input type="hidden" name="rno11" value="14045113011"/>
<input type="hidden" name="stdname11" value="Manzoor Ahmad Mir"/>
<input type="radio" id="att11" name="att11" value="P" />Present
<input type="radio" id="att11" name="att11" value="A" />Absent
<input type="radio" id="att11" name="att11" value="L" />Leave
</td></tr><tr><td>12</td><td>14045113012</td><td>Manzoor Ahmad Wani</td><td id=rid12>
<input type="hidden" name="rno12" value="14045113012"/>
<input type="hidden" name="stdname12" value="Manzoor Ahmad Wani"/>
<input type="radio" id="att12" name="att12" value="P" />Present
<input type="radio" id="att12" name="att12" value="A" />Absent
<input type="radio" id="att12" name="att12" value="L" />Leave
</td></tr><tr><td>13</td><td>14045113013</td><td>Shabir Ahmad Bhat</td><td id=rid13>
<input type="hidden" name="rno13" value="14045113013"/>
<input type="hidden" name="stdname13" value="Shabir Ahmad Bhat"/>
<input type="radio" id="att13" name="att13" value="P" />Present
<input type="radio" id="att13" name="att13" value="A" />Absent
<input type="radio" id="att13" name="att13" value="L" />Leave
</td></tr><tr><td>14</td><td>14045113014</td><td>Arshid Baba</td><td id=rid14>
<input type="hidden" name="rno14" value="14045113014"/>
<input type="hidden" name="stdname14" value="Arshid Baba"/>
<input type="radio" id="att14" name="att14" value="P" />Present
<input type="radio" id="att14" name="att14" value="A" />Absent
<input type="radio" id="att14" name="att14" value="L" />Leave
</td></tr><tr><td>15</td><td>14045113015</td><td>Ishtiyaq Ahmad</td><td id=rid15>
<input type="hidden" name="rno15" value="14045113015"/>
<input type="hidden" name="stdname15" value="Ishtiyaq Ahmad"/>
<input type="radio" id="att15" name="att15" value="P" />Present
<input type="radio" id="att15" name="att15" value="A" />Absent
<input type="radio" id="att15" name="att15" value="L" />Leave
</td></tr><tr><td>16</td><td>14045113016</td><td>Ishfaq Ahmad Bhat</td><td id=rid16>
<input type="hidden" name="rno16" value="14045113016"/>
<input type="hidden" name="stdname16" value="Ishfaq Ahmad Bhat"/>
<input type="radio" id="att16" name="att16" value="P" />Present
<input type="radio" id="att16" name="att16" value="A" />Absent
<input type="radio" id="att16" name="att16" value="L" />Leave
</td></tr><tr><td>17</td><td>14045113017</td><td>Sajad Ahmad Wani</td><td id=rid17>
<input type="hidden" name="rno17" value="14045113017"/>
<input type="hidden" name="stdname17" value="Sajad Ahmad Wani"/>
<input type="radio" id="att17" name="att17" value="P" />Present
<input type="radio" id="att17" name="att17" value="A" />Absent
<input type="radio" id="att17" name="att17" value="L" />Leave
</td></tr><tr><td>18</td><td>14045113018</td><td>Ajaz Ahmad</td><td id=rid18>
<input type="hidden" name="rno18" value="14045113018"/>
<input type="hidden" name="stdname18" value="Ajaz Ahmad"/>
<input type="radio" id="att18" name="att18" value="P" />Present
<input type="radio" id="att18" name="att18" value="A" />Absent
<input type="radio" id="att18" name="att18" value="L" />Leave
</td></tr><tr><td>19</td><td>14045113019</td><td>Waseem Ahmad</td><td id=rid19>
<input type="hidden" name="rno19" value="14045113019"/>
<input type="hidden" name="stdname19" value="Waseem Ahmad"/>
<input type="radio" id="att19" name="att19" value="P" />Present
<input type="radio" id="att19" name="att19" value="A" />Absent
<input type="radio" id="att19" name="att19" value="L" />Leave
</td></tr><tr><td>20</td><td>14045113020</td><td>Adil Ahmad Khan</td><td id=rid20>
<input type="hidden" name="rno20" value="14045113020"/>
<input type="hidden" name="stdname20" value="Adil Ahmad Khan"/>
<input type="radio" id="att20" name="att20" value="P" />Present
<input type="radio" id="att20" name="att20" value="A" />Absent
<input type="radio" id="att20" name="att20" value="L" />Leave
</td></tr>
<input type="hidden" id="rc" name="rc" value="20" />
<input type="hidden" name="Subject" value="C" />
<input type="hidden" name="Dept" value="MCA" />
<input type="hidden" name="Sem" value="1" />
<tr><td colspan="4" align="center"><input type="submit" value="Save"/> </td></tr></table>
</form>
You have duplicated IDs in your markup, fix it ASAP please.
Vanilla js solution
var areAllSelected = ![].filter.call(document.querySelectorAll("td[id]"), function(group) {
return [].every.call(group.querySelectorAll("input[type=\"radio\"]"), function(radio) {
return !radio.checked;
});
}).length
here's what you can do:
function check(){
var tableElem = document.getElementById('table'); //
for(var tr = 2; tr < tableElem.rows.length; tr++){
var isChecked = false;
for(var td = 0; td < tableElem.rows[tr].cells[3].children.length; td++ ){
var inputElem = tableElem.rows[tr].cells[3].children[td];
if(inputElem.type == "radio" && inputElem.checked) //check if at least one is checked
isChecked = true;
}
if(!isChecked)
return false;
}
return true;
}
the code to do this is as below.
thank all for the help.
But i have done it like this
function check()
{
var rc = document.getElementById("rc").value;
for(var i=1;i<=rc;i++)
{
var x="att"+i;
var y="rid"+i;
var len=document.getElementsByName(""+x).length;
var chk='No';
var radio=document.getElementsByName(""+x);
for(var j=0;j<len;j++)
if(radio.item(""+j).checked==true )
{
chk='Yes';
}
if(chk=='No')
{
document.getElementById(""+y).bgColor="Red";
document.getElementById(""+y).focus();
return false;
}
}
return true;
}
JS
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'Z'){
$('#Z').show();
}else{
$('#Z').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'A_A''){
$('#A_A').show();
}else{
$('#A_A'').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'B_B'){
$('#B_B').show();
}else{
$('#B_B').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'C_C'){
$('#C_C').show();
}else{
$('#C_C').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'D_D'){
$('#D_D').show();
}else{
$('#D_D').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'E_E'){
$('#E_E').show();
}else{
$('#E_E').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'F_F'){
$('#F_F').show();
}else{
$('#F_F').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'G_G'){
$('#G_G').show();
}else{
$('#G_G').hide();
}
});
$('p select[name=Membership_Selection]').change(function(e){
if ($('p select[name=Membership_Selection]').val() == 'H_H'){
$('#H_H').show();
}else{
$('#H_H').hide();
}
});
CSS
/*------------------------------------*\
Members Dropdown
\*------------------------------------*/
#A_A{display:none;}
#B_B{display:none;}
#C_C{display:none;}
#D_D{display:none;}
#E_E{display:none;}
#F_F{display:none;}
#G_G{display:none;}
#H_H{display:none;}
HTML
<div id="membership" align="right">
<p> <font size="2"><center><b>Become a Member</b></p></font></center>
<table>
<tbody><tr><td>
<p> <center> <font size="2">Alphabet Soup Membership Type</font></center></td></tr><tr><td>
<p><center>
<select name ="Membership_Selection" required>
<option value="Z">-- Select an Option --</option>
<option value="A_A">a a $5 year</option>
<option value="B_B">b b $10 year</option>
<option value="C_C">c c : $15 year</option>
<option value="D_D">d d $20 year</option>
<option value="E_E">e e $25 year</option>
<option value="F_F">f f : $30 year</option>
<option value="G_G">g g : $35 year</option>
<option value="H_H">h h : $40 year</option>
</select></center></p>
<center>
<form id="Z" target="paypal" action="" method="post">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal"></center>
</form>
<center>
<form id="A_A" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - AA">
<input type="hidden" name="item_number" value="AA">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="5">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="http://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="B_B" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - BB">
<input type="hidden" name="item_number" value="BB">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="10">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="C_C" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - CC">
<input type="hidden" name="item_number" value="CC">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="15">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php>
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="D_D" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - DD">
<input type="hidden" name="item_number" value="DD">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="20">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="E_E" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - EE">
<input type="hidden" name="item_number" value="EE">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="25">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="F_F" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - FF">
<input type="hidden" name="item_number" value="FF">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="30">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="G_G" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - GG">
<input type="hidden" name="item_number" value="GG">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="35">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
<center>
<form id="H_H" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Alpha Member - HH">
<input type="hidden" name="item_number" value="HH">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="40">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="return" value="https://example.com/thanks.php">
<input type="hidden" name="notify_url" value="https://example.com/pay_paypal/paypal.php">
<input class="memsubbut" value="Subscribe" type="submit" border="0" name="submit" alt="PayPal">
</form></center>
</td></tr>
</tbody>
</table>
</div><!-- #membership -->
What am I missing? I thought is was working in sandbox, but I guess didn't look closely.
Essentially, I hid all forms (buttons) in CSS. I then us JS to show them, but only one at a time.
Then HTML for the dropdown select. Is the problem in the JS, selecting the form?
Thanks in advance!
This FIDDLE BEGINS to help you with your problem.
$(document).ready(function () {
$('select[name=Membership_Selection]').change(function (e) {
switch ($(this).val()) {
case "A":
hideAllExcept($("#A"));
break;
case "B":
hideAllExcept($("#B"));
break;
case "C":
hideAllExcept($("#C"));
break;
default:
// do something defaultly
}
});
});
function hideAllExcept(toShow) {
toShow.show();
$("#membership").find('div').each(function () {
if ($(this).attr('id') != toShow.attr('id')) {
$(this).hide();
}
});
}
I had to remove A LOT of code so I could understand. Now you just need to paste some stuff in there and get to work.
Some hints:
1) Don't use center tag, like, ever;
2) Careful with some typos, like double single quotes when you only meant one. Also, 'a'
is different from 'a ', so be extra careful;
3) First, try to build the whole HTML BEFORE using styles (like the font tag, ew),
and style everything using CSS;
4) Don't use table as mean of styling;
5) Refator your code before continuing doing anything else, please.
This is NOT the entire answer you need, but it was what I was able to do.
I am trying to use function checkbox() to disable form submission.
Can anyone suggest what am i doing wrong?
Thanks in advance.
Here is the code snippet for the JS:
<script type = "text/javascript">
function checkbox() {
if(document.form.checkbox.checked)
{
document.form.submit.disabled=false;
}
else
{
document.form.submit.disabled=true;
}
}
</script>
And here is the HTML code.
<form name="form" action="shop_paypal.php" method="post">
<input name="cmd" type="hidden" value="_xclick" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="UK" />
<input name="currency_code" type="hidden" value="USD" />
<input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
<input type="hidden" name="item_name" id="item_name"value="YOUTUBE"/>
<select name="amount" id="amount" style="width:256px; height:32px;">
<option value="18" id="1">10,000 PINS - $18 </option>
<option value="35" id="2">20,000 PINS - $35</option>
<option value="75" id="3">30,000 PINS - $75</option>
<option value="140" id="4">50,000 PINS - $140</option>
</select>
<label>Your Facebook fan page URL: </label><br />
<input class="input-box" type="text" />
<input type="text" />
<input type="checkbox" class="checkbox" name="checkbox" id="checkbox"/>
<label class="agree">I agree to Terms & Conditions</label>
<input type="image" src="images/products/buynow.gif" class="submit" onclick= "checkbox();" name = "submit"/>
</form>
The obvious first thought would be:
var form = document.getElementsByTagName('form')[0];
function check (){
return document.getElementById('checkbox').checked;
}
form.addEventListener('submit', check);
Try this and notice how the function is simplyfied and calling is moved to the checkbox itself. When it's checked, button is enabled, and when unchecked, it's disabled (this is also a default state).
Here's also a working demo: http://jsfiddle.net/kL7We/
<script>
function enableSending() {
document.form.submit.disabled = !document.form.checkbox.checked;
}
</script>
<form name="form" action="shop_paypal.php" method="post">
<input name="cmd" type="hidden" value="_xclick" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="UK" />
<input name="currency_code" type="hidden" value="USD" />
<input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
<input type="hidden" name="item_name" id="item_name"value="YOUTUBE"/>
<select name="amount" id="amount" style="width:256px; height:32px;">
<option value="18" id="1">10,000 PINS - $18 </option>
<option value="35" id="2">20,000 PINS - $35</option>
<option value="75" id="3">30,000 PINS - $75</option>
<option value="140" id="4">50,000 PINS - $140</option>
</select>
<label>Your Facebook fan page URL: </label><br />
<input class="input-box" type="text" />
<input type="text" />
<input type="checkbox" class="checkbox" name="checkbox" id="checkbox" onclick= "enableSending();"/>
<label for="checkbox" class="agree">I agree to</label> Terms & Conditions
<input type="button" src="images/products/buynow.gif" class="submit" name = "submit" value="Send" disabled="disabled"/>