Click to See Complete Forum and Search --> : forms with text and combo boxes


byterunner
06-19-2003, 11:54 AM
Hi been debating with another programmer on my issue. hope you may put a little more light on my subject.
I have created a web form so that a user can make orders with ease here is the basis of how the page is setup

description (combo box 0-10) Price(textbox)

diskettes combo 7.99

Pencils combo 5.99

so that all my user has to do is choose the number of the specific item she wants from there when she hits TOTAL at the bottom of the page it multiplys the value in the combo box * the price of the item and totals it all up and displays the total in a text box at the bottom.

so this is what i have but it still doesn't pass any values to the text box.
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Lyreco Order Form</title>
<script language="javascript">

var diskettes=7.99;
var sony = 8.99;

function do_it()
{
var j=0;
var D1=0;
var totalitemcount = 83

while(j<totalitemcount)
{
var item = "document.order.item"+j+".options[document.order.item.selectedIndex]";
j++;

D1 += Number(eval(item).value)*diskettes;
D1 += Number(eval(item).value)*sony;
}

document.order.display.value = D1;

}

</script>

and here are my input button and textbox at the bottom

<input type="button" value="Total"
"onClick="do_it()"> <input type="text" name="display" size="10"><br>
<br>
</p>
</form>

<p>&nbsp;
</body>
</html>


either tell me i'm on the right track and hopefully tell me what i'm missin......or tell me a different approach.....i'm not a progerammer I have done lots(courses) but i've been a network admin for couple years now without programming

many thanks,

Khalid Ali
06-19-2003, 12:33 PM
it would have made more sense if you did this.

var item = eval("document.order.item"+j+".options[document.order.item.selectedIndex]");
j++;

D1 += Number(item.value)*diskettes;
D1 += Number(item.value)*sony;

Now it does not mean that the above will work,it willif there are not other problems in your code.
Th best thing if it doesn't work for you would be to post a link to your pages or post more code html+js

AdamBrill
06-19-2003, 12:35 PM
One problem that I noticed... In this line:<input type="button" value="Total" "onClick="do_it()"> <input type="text" name="display" size="10"><br> it should be this:<input type="button" value="Total" onClick="do_it()"> <input type="text" name="display" size="10"><br> I think it should work after that...

byterunner
06-20-2003, 09:49 AM
ok guys I have made changes, for the better, and thanks for picking up on that invalid quotation...god knows how many times i missed that......i think i liked COBOL better than this....lol....ok maybe thats going to hell with it....anyway here are the changes to my code , now i'm getting the following error
line = 22
char=1
error= 'value' is null or not an object
code=0

<script language="javascript">

var totalitemcount = 85;
cost = new Array(totalitemcount);
cost[0]=7.99;
cost[1]=8.99;
cost[2]=3.99;

function do_it()
{
var j=0;
var D1=0;

while(j<totalitemcount)
{
var item = "document.order.item"+j+".options[document.order.item.selectedIndex]";
var a = eval(item).value * cost[j];
j++;
D1 +=a

}

document.order.display.value = D1;

}

</script>

and here is a little html if it makes it a little easier...i can't post the page cause i'm just hosting it off my company workstation

<form name="order">
<input type="hidden" name="VTI-GROUP" value="0"><p><big><strong>Diskettes</strong></big>
CNIB</strong><br>
&font
size="3"> <strong>Quantity ; Box of 10 Sony Diskettes<strong> </strong>&nbsp; <select
name="item0" size="1">
<option value="0">0</option>
<option value="1">1 box</option>
<option value="2">2 boxes</option>
<option value="3">3 boxes</option>
<option value="4">4 boxes</option>
<option value="5">5 boxes</option>
<option value="6">6 boxes</option>
<option value="7">7 boxes</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="T2"
275 Sony Recordable CD-R &nbsp;&nbsp;<strong>&nbsp;&nbsp;&nbsp;</strong><select
name="item1" size="1">
<option value="0">0</option>
<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>
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="T26"
size="10"
style="font-family: Arial; font-size: 10pt; font-weight: bold; text-align: center; border: thin solid"


ii think i'm pretty close , i deleted what junk code i could so you could see how i'm calling the item's from the combo

many thanks

AdamBrill
06-20-2003, 09:54 AM
You have it set to 85 items... Do you have that many list boxes? My guess is that you don't have that many, thus causing an error when you try to call one that doesn't exist. If that isn't the problem, try attaching your entire page so we can look at the whole thing...

byterunner
06-20-2003, 01:28 PM
ok I have attached the page and yes i do have that many items. I need to add the code to reset the form as well think i seen that on my journeys.......I have added all items and named everything accordingly i think......it may be a bit messy I 've been using frontpage and have other things going on so haven't had the time to structure it properly but it is readable

cheers and thanks for you help

have a good weekend

AdamBrill
06-20-2003, 05:01 PM
Ok... Try the attached code and see if that works. It did something, so you just have to make sure it was doing the RIGHT something. :D lol...

byterunner
06-23-2003, 06:20 AM
cheers it work...........thanks dude......