﻿//these functions work together to create the ADD features of the orderList and post it as a form into CF

//helper function to create the form
function getNewSubmitForm(){
 var submitForm = document.createElement("FORM");
 document.body.appendChild(submitForm);
 submitForm.method = "POST";
 return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
 	var newElement = document.createElement("input");
	newElement.setAttribute("name", elementName);
	newElement.setAttribute("type", "hidden");
 	inputForm.appendChild(newElement);
 	newElement.value = elementValue;
 return newElement;
}

//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(posturl,productID,quantity,price,description){
 var submitForm = getNewSubmitForm();
 //inside the application.cfm waits the code looking for these values to do an ADD into the CF function
 createNewFormElement(submitForm, "productID", productID);
 createNewFormElement(submitForm, "quantity", quantity);
 createNewFormElement(submitForm, "price", price);
 createNewFormElement(submitForm, "description", description);
 createNewFormElement(submitForm, "orderListAdd", "1");
 submitForm.action= posturl;
 submitForm.submit();
}

