jsAllElectronics – Javascript Parts Ordering Script

I wanted a solution for making my visitors easier for them to order parts to build my projects. This code comes from the “Order By Part#” Page. Heres an example of how to use it:

<script type="text/javascript" src="//delphijustin.biz/wp-content/allelectronics.js"></script><!-- Load jsAllElectronics -->
<script type="text/javascript">
/* Here's how to call createAEForm
createAEForm(parts_Array,buttonText)
Parameters:
parts_Array Array of JSON objects containing parts Cat# and Qty
buttonnText Text inside of the button on the form.
*/

createAEForm([{Cat:"291-5.6K",Qty:10},{Cat:"293-10",Qty:10}],"Add Resistors to cart");//write form HTML to page
</script>

Heres the source code of the utility:

/*
Parts ordering script off of all electronics. This utility is not from all electronics and doesn't checks if all parts are in stock. If a part 
is not in stock all except parts that were not in stock will be added
jsAllElectronics by Justin Roeder www.delphijustin.biz
*/
function EnumParts(item,index){
var xitem=index+1;
document.writeln('<input type="hidden" name="id['+xitem+']" value="'+item.Cat+'"/>');
document.writeln('<input type="hidden" name="qty['+xitem+']" value="'+item.Qty+'"/>');
}
function createAEForm(parts,buttonText){
document.writeln('<form method="get" action="https://www.allelectronics.com/">');
document.writeln('<input type="hidden" name="type" value="" />');
document.writeln('<input type="hidden" name="page" value="item" />');
document.writeln('<input type="hidden" name="action" value="cart" />');
document.writeln('<input type="hidden" name="id" value="order_by_cat" />');
document.writeln('<input type="hidden" name="skip_redirect_suffix" value="" />');
parts.forEach(EnumParts);
document.writeln('<input type="submit" value="'+buttonText+'"></form>');
}

Real Example

Published by Justin Roeder

I am an electronics engineer and computer programmer that has autism. I learned by myself

delphijustin Industries is an Autism Supported Business
Social Media Auto Publish Powered By : XYZScripts.com
All in one
Start
Amazon.com, Inc. OH Dublin
Your cart is empty.
Loading...