Click to See Complete Forum and Search --> : JS for a form


lordofdavipers
10-04-2005, 11:30 PM
Hey all,

I have a particular food form that asks members to enter a specific numerical value per attending adult and/or child who will eat.
What I'd like to do is have the textbox for adult/child to be : $3.00 adults, $1.50 children.
So for example, when you have "2" in the adult box and "1" in children box, it will add 3.00+3.00+1.50 returning a total value to the guest.

Below is a script I made adding two variables, but it doesn't seem to apply to this situation.

<head><script>
function myAdder (box1, box2){
var total = box1 + box2
document.write(total)
}
</script>

</head>

<body>
<script>
document.write("<BR>")
myAdder(3.50, 3.50)
</script>
</body>

Here is the link to the form. link (http://jeffersonavenuebaptist.com/family_night_supper.htm)

I'm not the greatest with J/S and don't have full skills, so any help is appreceiated.

Thanks,

Andrew

jwlnewsome
10-05-2005, 06:02 AM
try this and modify
john

<head>
<script language "javascript">
function fun1 (num1,num2){
var price1 = 3;
var price2 = 2;
var total = (price1*num1)+(price2*num2);
document.form1.text1.value = total;
}
</script>
</head>
<body>
<form form name = "form1">
<input type = "text" name="textfield">
<input type = "text" name="textfield1">
<input type = "button" name="submit" value = "submit" onClick="fun1(form1.textfield.value ,form1.textfield1.value )">
<textarea name="text1" id = "text1" rows = "1" cols = "5"></textarea>
</form>
</body>

lordofdavipers
10-05-2005, 12:50 PM
Yes, from the looks of it it looks as if it will work fine. I will test it out when I get in this evening and let you know.

Thanks,

Andrew

lordofdavipers
10-05-2005, 09:17 PM
I tested your code jwlnewsome and I don't necessarily get an error, rather I know it's internal. This form is mixing with the main form and neither will process.
Here is a demo/dummy page with the same information from the original.

http://jeffersonavenuebaptist.com/fns2.htm

View source if you need. For now I left everthing as you posted it rather than the field resizes, colors, etc. so let me know what you find out.

(DISREGARD)Also jwlnewsome, would you know what to do to add a "$" in the total box? Not only as a preset, but as every entree has the "$" before it.(DISREGARD)
Update I put my JS skills to the test and figured that part out:
...
document.form1.text1.value = "$ " + total + " ¢";
...
It seems to enter the desired entree. Just need feedback on the top portion.

Thanks,

Andrew