I am trying to do a function that will perform automatic calculations based on user selections. I believe that the relevant values are stored in the array properly, but I am having trouble so that, for instance, if a user selects a template type from a drop down box, that the price associated with the template type is displayed in a text box. Here is my form code:
And here is my calculation JavaScript code so far:Code:<form id="website" name="website" action="mailto:apd15@hotmail.co.uk" method="post" onsubmit="return ValidatePaymentDetails();"> <p><b><u>Website Details Form</b></u></p> Website Template: <select id="templatetype" name="templatetype" onChange="getTotal()"> <option>Select a Template Type</option> <option value = "con">Construction</option> <option value = "it">IT</option> <option value = "eng">Engineering</option> <option value = "pub">Public Services</option> </select><br> Images? (£5 more per page): <input type="radio" name="images" value="Yes"/>Yes<input type="radio" name="images" value="No"/>No<br> Number Of Pages Desired (10 Maximum) : <select name="pagenum"> <option>Select A Number Of Pages</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> </select><br> Total Price:<input type="text" name="totalprice" id = "totalprice" readonly="readonly"><br> </form>
I would like the relevant price displayed in the "totalprice" text box, but I believe that a getElementByID line of code will be required, but I cannot seem to get it working when I tried.Code:function getTempPrice() { var template_type = new Array(); template_type[0]=10; template_type[1]=12; template_type[2]=14; template_type[3]=16; var tempPrice=0; var theForm = document.forms["website"]; var selectedTemplate=theForm.elements["templatetype"]; tempPrice = template_type[selectedTemplate.selectedIndex]; alert (tempPrice); return tempPrice; } function getTotal() { var webPrice = getTempPrice(); var result=document.forms["website"]["totalprice"] = webPrice; }
Any help is appreciated!![]()


Reply With Quote

Bookmarks