This is an old revision of the document!
Table of Contents
- type:
- integration
- system:
- ASP.NET
- name:
- jQuery Fake Forms for ASP.NET
- description:
- Workaround for ASP.NET's penchant to wrap the entire HTML body in a form tag, thus breaking all javascript that relies on forms' submit events.
- date:
- 2010-03-12
ASP.NET "Fake" Forms
Description
Because ASP.NET wraps the entire <body> section in a <form> tag, you cannot use forms in your pages, nor will the FoxyCart javascript behave as desired.
Installation
Copy or download the following code and save it on your server as form_fake.js. Put a <script> tag referencing it in the <head> section of your HTML, after your jQuery or foxycart_includes.js (or foxycart.js) call:
- form_fake.js
function form_fake(link) { parent = jQuery(link).closest('div.foxycart_form'); if (parent.length < 1) return false; console.info(link); console.info(parent); href = 'https://' + FoxyDomain + '/cart?' + jQuery(parent).find('*').serialize(); jQuery(link).attr('href', href); console.info(jQuery(link).attr('href')); } jQuery(document).ready(function($){ form_fake($('div.foxycart_form a.foxycart_submit')); $('div.foxycart_form a.foxycart_submit').click(function(){ form_fake($(this)); }); $('div.foxycart_form *').change(function(){ form_fake($(this).closest('div.foxycart_form').find('a.foxycart_submit')); }); });
- Change all your
form.foxycartelements todiv.foxycart_formelements. Remove the form-specific attributes likeaction,method, andaccept-charset. - Change your
input[type=submit]elements (or anything comparable) toa.foxycart.foxycart_submit. - Test.
So your HTML should look something like this:
<div class="foxycart_form"> <input type="hidden" name="name" value="Seats of CRM" /> <input type="hidden" name="discount_quantity_amount" value="Volume Discount{10-5}" /> <input type="hidden" name="price" value="54.99" /> <select name="sub_frequency"> <option value="1m">Monthly</option> <option value="1y{p:604.89}">Annual - 1st Month Free</option> </select> <a href="https://phase2.foxycart.com/cart" class="foxycart foxycart_submit">Submit</a> </div>