convert javascript to jquery using asp:button - c#

<script>
function addOption() {
document.getElementById('userType').value = "Error";
}function addOption1() {
document.getElementById('userType').value = "How";
}function addOption2() {
document.getElementById('userType').value = "Lifetouch";
}function addOption3() {
document.getElementById('userType').value = "Mobile";
}function addOption4() {
document.getElementById('userType').value = "Order";
} function addOption5() {
document.getElementById('userType').value = "Promotions";
} function addOption6() {
document.getElementById('userType').value = "Quality";
}
</script>
<select id="userType" disabled>
<option value="Select" selected id="myDefault">Select</option>
<option value="Error">Error</option>
<option value="How">How to</option>
<option value="Lifetouch">Lifetouch</option>
<option value="Mobile">Mobile app</option>
<option value="Order">Order status</option>
<option value="Promotions">Promotions</option>
<option value="Quality">Quality</option>
</select>
<button type="button" name="Error" onclick="addOption()">Error</button>
<button type="button" name="How to" onclick="addOption1()">How to</button>
<button type="button" name="Lifetouch" onclick="addOption2()">Lifetouch</button>
<button type="button" name="Mobile app" onclick="addOption3()">Mobile app</button>
<button type="button" name="Order status" onclick="addOption4()">Order status</button>
<button type="button" name="Promotions" onclick="addOption5()">Promotions</button>
<button type="button" name="Quality" onclick="addOption6()">Quality</button>
i want to change the asp:button event and jQuery any ideas

Consider the following example.
$(function() {
$("button.option").click(function() {
$("#userType").val($(this).attr("name").indexOf(" ") > -1 ? $(this).attr("name").substr(0, $(this).attr("name").indexOf(" ")) : $(this).attr("name"));
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="userType" disabled>
<option value="Select" selected id="myDefault">Select</option>
<option value="Error">Error</option>
<option value="How">How to</option>
<option value="Lifetouch">Lifetouch</option>
<option value="Mobile">Mobile app</option>
<option value="Order">Order status</option>
<option value="Promotions">Promotions</option>
<option value="Quality">Quality</option>
</select>
<button type="button" name="Error" class="option">Error</button>
<button type="button" name="How to" class="option">How to</button>
<button type="button" name="Lifetouch" class="option">Lifetouch</button>
<button type="button" name="Mobile app" class="option">Mobile app</button>
<button type="button" name="Order status" class="option">Order status</button>
<button type="button" name="Promotions" class="option">Promotions</button>
<button type="button" name="Quality" class="option">Quality</button>
In the future, please provide a proper example and clear definition of what you are trying to accomplish. You will also want to include any examples of code you have tried. Please also take the Tour.

Related

How to send dynamic amount of HTML forms to controller as list of objects?

I am doing a .NET Core MVC project. In a partial view, I want some information from user to fill as HTML form. That information is variables of a model, so every filled list is an object. After user filled the objects, I want to send that object to my controller as a List of that object. User may send 3 forms or 5 forms or 1 form. My question is, when it is only 1 form to send, everything was ok, I gave variables names' of model as name attribute to my HTML inputs in a form tag and my object was filling. But in that case which I don't know how many objects will come, I could not figure out how can I get list of objects. I hope it is clear.
Here is my View:
#model List<EpubAdmin.Models.KyProducts>
#{
ViewData["Title"] = "AddBook";
Layout = null;
}
#foreach(var product in Model)
{
<div class="col col-xl-12">
<div class="row justify-content-center">
<div class="col-xl-5 col-lg-5 ">
<form method="post" action="/File/AddProductFile" enctype="multipart/form-data" id="myForm">
<br />
<b>Kitap Adı: </b>
<input class="form-control" value="#(Html.Raw(product.Name))" name="Name"/>
<br />
<b>Sayfa Sayısı: </b>
<input class="form-control" value="#product.PageNumber" name="PageNumber" />
<br />
<b>Product Id: </b>
<input class="form-control" value="#product.KyProductId" name="KyProductId" readonly />
<br />
<b>Barkod: </b>
<input class="form-control" value="#product.Barcode" name="Barcode" readonly />
<input class="form-control" value="#product.Author" name="Author" hidden />
<input class="form-control" value="#product.ImageId" name="ImageId" hidden />
<input class="form-control" value="#product.PublisherName" name="PublisherName" hidden />
<input class="form-control" value="#product.PublisherId" name="PublisherId" hidden />
<br />
#*<select class="selectpicker" data-live-search="true" data-show-subtext="true">
<option value="0">Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>*#
#if (product.IsDuplicate)
{
<div class="alert alert-danger">
<p>* Bu kitap zaten ekli.</p>
</div>}
else
{
<h5>Kategori Seç</h5>
<select class="form-select ml-0" data-live-search="true">
<option selected>Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>
<select class="form-select ml-5">
<option selected>Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>
<select class="form-select ml-5">
<option selected>Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>
<br />
<br />
<label for="file">Yüklenecek kitabı seçin.</label>
<input type="file" class="form-control-file" id="File" accept=".epub" name="File">
}
</form>
<br />
<br />
</div>
</div>
<br />
<hr />
<br />
</div>
}
<div class="float-right">
<button class="btn btn-info w-100" onclick="onclk()">Ekle</button>
</div>
<br />
<br />
<script>
function onclk() {
$("#myForm").submit();
alert("a");
}
</script>
Controller:
[HttpPost]
public IActionResult AddProductFile(List<KyProducts> model)
{
foreach(var product in model)
{
if (product.file == null || product.KyProductId == 0 || product.PublisherId == 0)
{
return RedirectToAction("List", "Books");
}
}
}
I thought about using for instead of foreach in my view so I can get indexes and can name my HTML attributes as name="id+#i" but that did not seem best practice to me and wasn't sure if it works. I also thought about putting hidden submit buttons for every form and on click of main submit button, triggering all hidden submit buttons but that didn't seem to be best practice again... What are your ideas?
If you want to pass a list to your action,try to put the form outside foreach,and change the name of inputs:
#model List<EpubAdmin.Models.KyProducts>
#{
ViewData["Title"] = "AddBook";
Layout = null;
}
<form method="post" action="/File/AddProductFile" enctype="multipart/form-data" id="myForm">
#{ var i = 0;}
#foreach (var product in Model)
{
<div class="col col-xl-12">
<div class="row justify-content-center">
<div class="col-xl-5 col-lg-5 ">
<br />
<b>Kitap Adı: </b>
<input class="form-control" value="#(Html.Raw(product.Name))" name="model[#i].Name" />
<br />
<b>Sayfa Sayısı: </b>
<input class="form-control" value="#product.PageNumber" name="model[#i].PageNumber" />
<br />
<b>Product Id: </b>
<input class="form-control" value="#product.KyProductId" name="model[#i].KyProductId" readonly />
<br />
<b>Barkod: </b>
<input class="form-control" value="#product.Barcode" name="model[#i].Barcode" readonly />
<input class="form-control" value="#product.Author" name="model[#i].Author" hidden />
<input class="form-control" value="#product.ImageId" name="model[#i].ImageId" hidden />
<input class="form-control" value="#product.PublisherName" name="model[#i].PublisherName" hidden />
<input class="form-control" value="#product.PublisherId" name="model[#i].PublisherId" hidden />
<br />
#if (product.IsDuplicate)
{
<div class="alert alert-danger">
<p>* Bu kitap zaten ekli.</p>
</div>}
else
{
<h5>Kategori Seç</h5>
<select class="form-select ml-0" data-live-search="true">
<option selected>Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>
<select class="form-select ml-5">
<option selected>Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>
<select class="form-select ml-5">
<option selected>Tarih</option>
<option value="1">Çocuk</option>
<option value="2">Psikoloji</option>
<option value="3">Kültür</option>
</select>
<br />
<br />
<label for="file">Yüklenecek kitabı seçin.</label>
<input type="file" class="form-control-file" id="File" accept=".epub" name="File">
}
<br />
<br />
</div>
</div>
<br />
<hr />
<br />
</div>
i++;
}
<input type="submit" value="submit"/>
</form>
So that when you click the button,it will pass the whole list to action.

Select Tag Option Value not passing to url parameter on iOS

I have a set of html select tags that serve to accomplish a a set of search parameters for a vehicle catalogue.
The html is as follows:
<div class="clearfix select-form padding-bottom-50">
<div class="my-dropdown min-years-dropdown max-dropdown">
<select name="year" class="css-dropdowns" tabindex="1" id="txtYear" runat="server" >
<option value="">Search by Year</option>
<option value="2018">2018</option>
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
</select>
</div>
<div class="my-dropdown min-years-dropdown max-dropdown">
<select name="make" class="css-dropdowns" tabindex="1" id="txtMake" runat="server" >
<option value="">Search by Make</option>
<option value="BMW">BMW</option>
<option value="FORD">FORD</option>
</select>
</div>
<div class="my-dropdown min-years-dropdown max-dropdown">
<select name="transmission" class="css-dropdowns" tabindex="1" id="txtTrans" runat="server" >
<option value="">Search by Transmission</option>
<option value="Automatic">Automatic</option>
<option value="Manual">Manual</option>
</select>
</div>
<div class="my-dropdown min-years-dropdown max-dropdown">
<select name="price" class="css-dropdowns" tabindex="1" id="txtPrice" runat="server" >
<option value="">Search by Price</option>
<option value="50000">< R50,000</option>
<option value="100000">< R100,000</option>
<option value="150000">< R150,000</option>
<option value="200000">< R200,000</option>
</select>
</div>
<input type="button" value="Search" class="pull-left btn-inventory margin-bottom-none md-button" runat="server" id="btnSearch" onserverclick="btnSearch_ServerClick1" />
</div>
</div>
<div class="clearfix"></div>
</div>
On Codebehind:
protected void btnSearch_ServerClick1(object sender, EventArgs e)
{
Response.Redirect("usedsearch.aspx?make=" + txtMake.Value + "&year=" + txtYear.Value + "&trans=" + txtTrans.Value + "&price=" + txtPrice.Value);
}
When browsing the site on an iphone, the values from the select tags are not passed to the URL Parameters(Parameter value is blank -> eg www.....com?Make=&Year=...).
However, on an android device, it works perfectly. Really confused.

How to get text in html textbox using aspx c# and display it

So for a school project I need to create login + sign up forms using aspx files.
I decided to make it one page 2 forms style that changes the form on a button press.
Now what I need to do at this point is to display the entered username after pressing the submit button in a new page.
this is the HTML
<%--Register--%>
<section>
<div id="container_demo">
<!-- hidden anchor to stop jump -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form autocomplete="on" runat="server" name="signin" method="post" id="signin">
<h1>התחבר</h1>
<p>
<label for="username" class="uname" data-icon="u">אימייל או שם משתמש: </label>
<input <%--id="username"--%> id="signUsername" required="required" type="text" placeholder="myusername or mymail#mail.com" />
</p>
<p>
<label for="password" class="youpasswd" data-icon="p">סיסמה : </label>
<input id="lPassword" name="password" required="required" type="password" placeholder="eg. X8df!90EO" />
</p>
<p class="keeplogin">
<label for="loginkeeping">השאר אותי מחובר</label>
<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
</p>
<p class="login button">
<input type="submit" value="התחבר" />
</p>
<p class="change_link">
אין משתמש?
הצטרף
</p>
</form>
</div>
<div id="register" class="animate form">
<form action="mysuperscript.php" autocomplete="on" onsubmit="return checkForm()">
<h1>הירשם </h1>
<p>
<label for="usernamesignup" <%--class="uname"--%> data-icon="u">שם משתמש</label>
<input id="usernamesignup" name="loginUsername" required="required" type="text" placeholder="mysuperusername690" pattern=".{3,}" oninvalid="this.setCustomValidity('שם משתמש קצר')" oninput="setCustomValidity('')" />
</p>
<p>
<label for="fNmae" class="fname" data-icon="u">שם פרטי</label>
<input id="fName" class="fnamesign" required="required" type="text" placeholder="איציק" />
</p>
<p>
<label for="lName" class=" lNaem" data-icon="u">שם משפחה</label>
<input id="lName" class="lNamesign" required="required" type="text" placeholder="פלדמן" />
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e">אימייל</label>
<input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="mysupermail#mail.com" />
</p>
<p>
<label for="Password" class="youpasswd" data-icon="p">סיסמה </label>
<input id="Password" name="passwordsignup" required="required" type="password" placeholder="eg. X8df!90EO" />
</p>
<p>
<label for="cPassword" class="youpasswd" data-icon="p">אשר סיסמה </label>
<input id="cPassword" name="passwordsignup_confirm" required="required" type="password" placeholder="eg. X8df!90EO" />
</p>
<label for="bday">יום הולדת</label>
<p id="birthday">
<select name='day' id='dayddl'>
<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>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
<select name='month' id='monthddl'>
<option value='1'>ינואר</option>
<option value='2'>פבואר</option>
<option value='3'>מרץ</option>
<option value='4'>אפריל</option>
<option value='5'>מאי</option>
<option value='6'>יוני</option>
<option value='7'>יולי</option>
<option value='8'>אוגוסט</option>
<option value='9'>ספטמבר</option>
<option value='10'>אוקטובר</option>
<option value='11'>נובמבר</option>
<option value='12'>דצמבר</option>
</select>
<input id="byear" name="byear" required="required" type="number" placeholder="2016" min="1970" max="2016" />
</p>
<p id="tel">
<label for="phone">מספר טלפון</label>
<br />
<input type="text" maxlength="3" id="phone" placeholder="050" class="bphone" />
-
<input type="text" maxlength="7" placeholder="1234567" class="ephone" />
</p>
<div id="mof">
<p>
<label for="gedner">מין</label>
<br />
<input type="radio" name="gender" value="male" checked />זכר
<input type="radio" name="gender" value="female" />נקבה
</p>
<p>
<label>סגנון האהוב</label>
<br />
<input type="radio" name="style" value="rock" required="required" />רוק
<br />
<input type="radio" name="style" value="metal" required="required" />מאטל
<br />
<input type="radio" name="style" value="classic" required="required" />
קלאסי
<br />
</p>
</div>
<p class="signin button">
<input type="submit" value="הירשם" id="sub" />
</p>
<p class="change_link">
יש משתמש ?
התחבר
</p>
</form>
</div>
</div>
</div>
</section>
</div>
And this .cs file
public partial class Login_N_register_ : System.Web.UI.Page
{
public string st = "";
protected void Page_Load(object sender, EventArgs e)
{
//Signin vars
string signUser = ((TextBox)signin.FindControl("signUsername")).Text;
//Login vars
string loginUser = Request.Form["loginUsername"];
st +="<h3 style='postition:absolute;top:50%;z-index:999;'>"+ signUser+"</h3>";
}
}
For some reason the .cs file won't show the entered text.
Didn't get to it because I want able to make one form to work but because its a 2 form one page I need it to only display the textbox which is on the page for example:
I log in as: x: nothing that relates to the signup form won't run and after pressing submit the .cs file add it to MasterPage code and I will be transferred to a new page (action="Main.master" I think)
And the other why around
Hope I was clear thanks in advanced

Asp.net dynamic dropdownlist access with jquery

I am creating a dynamic dropdownlist in asp.net which is under asp:listview control code is as below:
<asp:ListView runat="server" ID="lst" OnItemDataBound="lst_dataBound">
<ItemTemplate>
<asp:DropDownList runat="server" CssClass="test" ID="ddl"></asp:DropDownList>
<asp:HiddenField runat="server" ID="hf" Value='<%# Eval("Id") %>' />
<a class="btn btn-success" id='<%#Eval("ID") %>' onclick="Add('<%#Eval("ID")%>')>Add</a>
</ItemTemplate>
</asp:ListView>
on the server side I have given source and bind the list and on item databound event I have bound dropdownlist which is perfectly but as shown above when I click on an anchor tag I want selected item from drop down for that I have tried this:
var item = $('.test option:selected').text();
alert(item);
which is giving me all list items like if i have 10 list so 10 dropdowns so if each have 4 items take text as(1,2,3,4)
selected item at each list so randomly it will ("1212134232") which is 10 item in alert but I want single one so I tried another solution I give dynamic cssclass at server side like this
DropDownList myDDL = (DropDownList)e.Item.FindControl("ddl");
HiddenField HF_ID = (HiddenField)e.Item.FindControl("hf");
myDDL.ID = "test" + HF_ID.Value;
so now I have dynamic class name I can access them at jQuery - JavaScript
so code which I use them for is
here id is which I will get from function parameter
var test = "test" + id;
var item = $('.test option:selected').text();
alert(item);
here it should give the right answer but it is not giving it so I try further I inspect element and see if this working and yes its working dynamic css class they have so I have think further and tried like if dynamic side name given like
test20, test21, etc...
y not try static value so I tried
var item = $('.test20 option:selected').text();
alert(item);
and yes its working it is giving me specific dropdown list selected value but this can't be done for statically so I needed help here.
rendered html is:
<select class="test29" id="ContentPlaceHolder1_lst_ddl_5" name="ctl00$ContentPlaceHolder1$lst$ctrl5$ddl">
<option value="85">1</option>
<option value="86">2</option>
<option value="87">3</option>
<option value="88">4</option>
</select>
screen shot of clicking element alert dialog which should give test29(1234(one of them))
but getting....
<div class="col-xs-12 col-ms-6 col-sm-4 col-md-3 col-lg-3">
<select name="ctl00$ContentPlaceHolder1$lst$ctrl0$ddl" id="ContentPlaceHolder1_lst_ddl_0" class="test23">
<option value="65">1</option>
<option value="66">2</option>
<option value="67">3</option>
<option value="68">4</option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$lst$ctrl0$hf" id="ContentPlaceHolder1_lst_hf_0" value="23">
<a class="btn btn-success" id="23" onclick="Add('23')">
Add</a>
</div>
<div class="col-xs-12 col-ms-6 col-sm-4 col-md-3 col-lg-3">
<select name="ctl00$ContentPlaceHolder1$lst$ctrl1$ddl" id="ContentPlaceHolder1_lst_ddl_1" class="test25">
<option value="69">1</option>
<option value="70">2</option>
<option value="71">3</option>
<option value="72">4</option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$lst$ctrl1$hf" id="ContentPlaceHolder1_lst_hf_1" value="25">
<a class="btn btn-success" id="25" onclick="Add('25')">
Add </a>
</div>
<div class="col-xs-12 col-ms-6 col-sm-4 col-md-3 col-lg-3">
<select name="ctl00$ContentPlaceHolder1$lst$ctrl2$ddl" id="ContentPlaceHolder1_lst_ddl_2" class="test26">
<option value="73">1</option>
<option value="74">2</option>
<option value="75">3</option>
<option value="76">4</option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$lst$ctrl2$hf" id="ContentPlaceHolder1_lst_hf_2" value="26">
<a class="btn btn-success" id="26" onclick="Add('26')">
Add</a>
</div>
<div class="col-xs-12 col-ms-6 col-sm-4 col-md-3 col-lg-3">
<select name="ctl00$ContentPlaceHolder1$lst$ctrl3$ddl" id="ContentPlaceHolder1_lst_ddl_3" class="test27">
<option value="77">S</option>
<option value="78">M</option>
<option value="79">L</option>
<option value="80">XL</option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$lst$ctrl3$hf" id="ContentPlaceHolder1_lst_hf_3" value="27">
<a class="btn btn-success" id="27" onclick="Add('27')">
Add</a>
</div>
<div class="col-xs-12 col-ms-6 col-sm-4 col-md-3 col-lg-3">
<select name="ctl00$ContentPlaceHolder1$lst$ctrl4$ddl" id="ContentPlaceHolder1_lst_ddl_4" class="test28">
<option value="81">1</option>
<option value="82">2</option>
<option value="83">3</option>
<option value="84">4</option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$lst$ctrl4$hf" id="ContentPlaceHolder1_lst_hf_4" value="28">
<a class="btn btn-success" id="28" onclick="Add('28')">
Add</a>
</div>
any other info needed?
You can try below code to get the selected value of dropdown in same list item. you need to write it in click event handler so that this will give the invoker object and that will help to find the nearest dropdown in same list item.
$(this).siblings("select").find(":selected").val()

How to implement DoDirectPayment in paypal using c#

I am newbie to paypal. I want to implement direct payment api for my website. Means i will be having a buy button when i click on that it will expand and in that iframe i will be having the url for paypal direct payment. I have written the code like
string address = "https://api-3t.sandbox.paypal.com/nvp?USER=user&COUNTRYCODE=US&ZIP=95131&STATE=CA&CITY=San Jose&FIRSTNAME=John&LASTNAME=Smith&STREET=1asfasdfSt&CVV2=123&ACCT=4683075410516684&IPADDRESS=192.168.0.62&PWD=1357635822&EXPDATE=042011&VERSION=58.0&SIGNATURE=signature&METHOD=DoDirectPayment&CREDITCARDTYPE=Visa&AMT=10.00&PAYMENTACTION=Sale&RETURNURL=http://returnurl&CANCELURL=http://cancnelurl";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
Stream stream = response2.GetResponseStream();
StreamReader rdr = new StreamReader(stream);
string req = rdr.ReadToEnd();
But the req contains the failure message. I don't know what credentials i am missing.
Any help is appreciated.
The error message states that its the expiry date thats the problem.
You are passing EXPDATE=042011 which looks to me like a date in the past.
Edit:
10500 Invalid Configuration This transaction cannot be processed due to an invalid merchant configuration.
Occurs when you have not agreed to the billing agreement.
10501 Invalid Configuration This transaction cannot be processed due to an invalid merchant configuration.
Occurs when the billing agreement is disabled or inactive.
As it was already mentioned, the error that you are getting is because pro is not enabled on the account you are using the credentials for. Express Checkout does not require any special billing agreement, this is why your Express Checkout calls were working.
I have enabled to pro service on your test sandbox account, and you should be able to test with it now.
<html>
<head>
<title>PayPal Merchant SDK - DoDirectPayment API</title>
<link rel="stylesheet" href="../Common/sdk.css"/>
<script language="JavaScript">
function generateCC(){
var cc_number = new Array(16);
var cc_len = 16;
var start = 0;
var rand_number = Math.random();
switch(document.DoDirectPaymentForm.creditCardType.value)
{
case "Visa":
cc_number[start++] = 4;
break;
case "Discover":
cc_number[start++] = 6;
cc_number[start++] = 0;
cc_number[start++] = 1;
cc_number[start++] = 1;
break;
case "MasterCard":
cc_number[start++] = 5;
cc_number[start++] = Math.floor(Math.random() * 5) + 1;
break;
case "Amex":
cc_number[start++] = 3;
cc_number[start++] = Math.round(Math.random()) ? 7 : 4 ;
cc_len = 15;
break;
}
for (var i = start; i < (cc_len - 1); i++) {
cc_number[i] = Math.floor(Math.random() * 10);
}
var sum = 0;
for (var j = 0; j < (cc_len - 1); j++) {
var digit = cc_number[j];
if ((j & 1) == (cc_len & 1)) digit *= 2;
if (digit > 9) digit -= 9;
sum += digit;
}
var check_digit = new Array(0, 9, 8, 7, 6, 5, 4, 3, 2, 1);
cc_number[cc_len - 1] = check_digit[sum % 10];
document.DoDirectPaymentForm.creditCardNumber.value = "";
for (var k = 0; k < cc_len; k++) {
document.DoDirectPaymentForm.creditCardNumber.value += cc_number[k];
}
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
<h3>DoDirectPayment</h3>
<div id="apidetails">Process a credit card payment.</div>
</div>
<div id="request_form">
<form method="POST" action="DoDirectPayment.php"
name="DoDirectPaymentForm">
<div class="params">
<div class="param_name">Payment type</div>
<div class="param_value">
<select name="paymentType">
<option value="Sale" selected="selected">Sale</option>
<option value="Authorization">Authorization</option>
</select>
</div>
</div>
<div class="params">
<div class="param_name">First name</div>
<div class="param_value">
<input type="text" name="firstName" value="John"/>
</div>
</div>
<div class="params">
<div class="param_name">Last name</div>
<div class="param_value">
<input type="text" name="lastName" value="Doe"/>
</div>
</div>
<div class="params">
<div class="param_name">Card type</div>
<div class="param_value">
<select name="creditCardType"
onChange="javascript:generateCC(); return false;">
<option value="Visa" selected="selected">Visa</option>
<option value="MasterCard">MasterCard</option>
<option value="Discover">Discover</option>
<option value="Amex">American Express</option>
</select>
</div>
</div>
<div class="params">
<div class="param_name">Card number</div>
<div class="param_value">
<input type="text" size="19" maxlength="19" name="creditCardNumber">
</div>
</div>
<div class="params">
<div class="param_name">Expiry date</div>
<div class="param_value">
<select name="expDateMonth">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="expDateYear">
<option value="2013">2013</option>
<option value="2014" selected>2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div>
</div>
<div class="params">
<div class="param_name">CVV</div>
<div class="param_value">
<input type="text" size="3" maxlength="4" name="cvv2Number" value="962">
</div>
</div>
<div class="params">
<div class="param_name">Amount</div>
<div class="param_value">
<input type="text" size="5" maxlength="7" name="amount" value="1.00"> USD
</div>
</div>
<div class="section_header">Billing address</div>
<div class="params">
<div class="param_name">Address 1</div>
<div class="param_value">
<input type="text" size="25" maxlength="100" name="address1" value="1 Main St">
</div>
</div>
<div class="params">
<div class="param_name">Address 2 (optional)</div>
<div class="param_value">
<input type="text" size="25" maxlength="100" name="address2" value="">
</div>
</div>
<div class="params">
<div class="param_name">City</div>
<div class="param_value">
<input type="text" size="25" maxlength="40" name="city" value="San Jose">
</div>
</div>
<div class="params">
<div class="param_name">State</div>
<div class="param_value">
<select id=state name="state">
<option value=""></option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA" selected>CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DC">DC</option>
<option value="DE">DE</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="IA">IA</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="MA">MA</option>
<option value="MD">MD</option>
<option value="ME">ME</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MO">MO</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="NE">NE</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="NY">NY</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VA">VA</option>
<option value="VT">VT</option>
<option value="WA">WA</option>
<option value="WI">WI</option>
<option value="WV">WV</option>
<option value="WY">WY</option>
<option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AS">AS</option>
<option value="FM">FM</option>
<option value="GU">GU</option>
<option value="MH">MH</option>
<option value="MP">MP</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="VI">VI</option>
</select>
</div>
</div>
<div class="params">
<div class="param_name">Zip code</div>
<div class="param_value">
<input type="text" size="10" maxlength="10" name="zip" value="95131"> (5 or 9 digits)
</div>
</div>
<div class="params">
<div class="param_name">Country</div>
<div class="param_value">
<input type="text" size="10" maxlength="10" name="country" value="US">
</div>
</div>
<div class="params">
<div class="param_name">Phone</div>
<div class="param_value">
<input type="text" size="10" maxlength="10" name="phone" value="">
</div>
</div>
<div class="params">
<div class="param_name">IPN listener URL</div>
<div class="param_value">
<input type="text" size="80" maxlength="200" name="notifyURL" value="">
</div>
</div>
<div class="params">
<div class="param_name"></div>
<div class="param_value">
</div>
</div>
<div class="submit">
<input type="submit" name="DoDirectPaymentBtn"
value="DoDirectPayment" />
</div>
</form>
Home
</div>
</div>
<script language="javascript">
generateCC();
</script>
</body>
</html>

Categories