-
javascript help
I need a JS check box calculator
As in:
Like a list of check boxes as options to purchase
And it gives a total at bottom and have a submit button to send this info via email
kind of like a shopping cart with no money or CC
just the info of what you want to buy
OH it needs to work cross browser too
thanks
any direction would be great
-
No!
Re: javascript help
Originally posted by CWC-oneshot
OH it needs to work cross browser too
You might want to look into php or asp instead, as javascript is somewhat difficult to work in all browsers. Remember some people still use netscape 4.7.
And then there's always the people who just turn javascript off to avoid other things like pop-ups.
If you're still set on using javascript, then post some more info on what your page looks like (perhaps a link to the actual page you will be using for this)
-
PHP would be great! I just dont know it hehehehe
I guess I can start looking at resource sites for php calculators?
Its just s list of items or options each has a dollar amount per person then I need a total at bottom so they see where they are at moneywise
BUT it needs a blank text field thats call HOW MANY PEOPLE
then they put in amount and it adds does the math to show how much it will cost per person and as a total amount.
then a submit button that send this info and the name address stuff they fill out all to an email
hehehehehe
please point me in direction of script hehe
If you can make it maybe we can do a trade I am very good with logos and any thing photoshop I can produce pro level artwork. =)
maybe you need a little logo work on your site hmmm?
have a great day!
Last edited by CWC-oneshot; 12-03-2003 at 12:51 AM.
-
No!
Well, if your offering to make me a logo, then I wouldn't pass up your offer.
The site's http://www.bitwiseor.com
as you can see from that, I'm don't care much for images on my web pages, but I'm willing to use a logo if I had one.
Here's a simple example of what I think you want. I can't connect to my server right now for some odd reason, so here's the code and you can copy/paste into your own web page.
It uses the standard javascript DOM, so it should work on IE 5+, netscape 6+, Opera 6+, Mozilla/firebird 1+, and Safari from what I'm aware.
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
function updateTotal(){
var total = 0;
cb = document.getElementById("one_dollar");
if(cb.checked) total += eval(cb.value);
cb = document.getElementById("two_dollars");
if(cb.checked) total += eval(cb.value);
cb = document.getElementById("four_dollars");
if(cb.checked) total += eval(cb.value);
cb = document.getElementById("eight_dollars");
if(cb.checked) total += eval(cb.value);
cb = document.getElementById("sixteen_dollars");
if(cb.checked) total += eval(cb.value);
hm = document.getElementById("howmany");
if(!isNaN(hm.value) && hm.value > 0) total = total/hm.value;
ttl = document.getElementById("total");
ttl.value = total;
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<p>
<input type="checkbox" id="one_dollar" value="1">
$1<br>
<input type="checkbox" id="two_dollars" value="2">
$2<br>
<input type="checkbox" id="four_dollars" value="4">
$4<br>
<input type="checkbox" id="eight_dollars" value="8">
$8<br>
<input type="checkbox" id="sixteen_dollars" value="16">
$16<br>
<input id="howmany" type="text" value="1" size="16" maxlength="16">
How Many<br>
<input name="update" type="button" onClick="javascript:updateTotal();" value="Update">
</p>
<p>
<input name="total" type="text" readonly="true" id="total" size="16" maxlength="16">
Total </p>
</form>
</body>
</html>
-
I was thinking more in the line of what you have here but in PHP
something a little more dependable.
is this OK?
i will make a nice logo just tell me one or two colors you like and if you want it more techy or more natural looking.
Im doing some real nice Japanese looking things right now maybe you would like that.
I think it would suit your site because it looks so clean and defined.
Here is what I mean by Japanese
(this is a work in prog.)hehe
dont look if your dial up!!!! it may load slow right now
my new site (not finished)
let me know
peace
One
Last edited by CWC-oneshot; 12-03-2003 at 04:24 AM.
-
No!
ugh, sorry for the delay in reply, but here it is in PHP. (I've had many term projects this semester)
PHP Code:
<?php
function getValue(){
$v = 0;
if(isset($_POST['one_dollar'])){
$v += $_POST['one_dollar'];
}
if(isset($_POST['two_dollars'])){
$v += $_POST['two_dollars'];
}
if(isset($_POST['four_dollars'])){
$v += $_POST['four_dollars'];
}
if(isset($_POST['eight_dollars'])){
$v += $_POST['eight_dollars'];
}
if(isset($_POST['sixteen_dollars'])){
$v += $_POST['sixteen_dollars'];
}
if($_POST['howmany'] > 0){
$v = $v / $_POST['howmany'];
}
echo $v;
}
?>
<html>
<head>
<title> Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="<? $_SERVER['PHP_SELF'] ?>">
<p>
<input type="checkbox" name="one_dollar" value="1" <? if(isset($_POST['one_dollar'])) echo "checked"; ?>>
$1<br>
<input type="checkbox" name="two_dollars" value="2" <? if(isset($_POST['two_dollars'])) echo "checked"; ?>>
$2<br>
<input type="checkbox" name="four_dollars" value="4" <? if(isset($_POST['four_dollars'])) echo "checked"; ?>>
$4<br>
<input type="checkbox" name="eight_dollars" value="8" <? if(isset($_POST['eight_dollars'])) echo "checked"; ?>>
$8<br>
<input type="checkbox" name="sixteen_dollars" value="16" <? if(isset($_POST['sixteen_dollars'])) echo "checked"; ?>>
$16<br>
<input name="howmany" type="text" size="16" maxlength="16" <? if(isset($_POST['howmany'])) {echo "value=\"".$_POST['howmany']."\"";} else {echo "value=\"1\"";} ?>>
How Many<br>
<input name="update" type="submit" value="Update">
</p>
<p>
<input name="total" type="text" readonly="true" id="total" size="16" maxlength="16" value="<? getValue(); ?>">
Total </p>
</form>
</body>
</html>
You can see an example at www.bitwiseor.com/updateVal.php
-
WOW
Gosh I need to learn PHP it looks very neat and clean.
only it did not work =( when I changed the number of people and updated
it does work if I leave it set for 1 howmany
but if I make it 3 people it messes up
Is this easy to fix?
I am grateful for your help
One
-
No!
how do you mean that it did not work? The code works on the sample that I uploaded. ie. checking $2 and $4 and setting howmany to 3 gives 2
(2 + 4) / 3 = 6 / 3 = 2
Or do you mean that the decimal repeats? like when you check 2 and set howmay to 3 it gives .666666...?
[edit]
The last thing I mentioned is fixed by changing the one line in changeVal where the division occurs
PHP Code:
if($_POST['howmany'] > 0){
$v = floor(100 * ($v / $_POST['howmany'])) / 100;
}
echo $v;
A sample can be found at www.bitwiseor.com/updateVal2.php
[/edit]
j
Last edited by yasunobu13; 12-09-2003 at 02:17 PM.
-
hmmmm
Hello!
What I mean is
If you check the 2$ box only
and then type a 2 in the HOW MANY PEOPLE input field.
in formula it would be at $2 a person X 2 people = 4 dollars
So when you hit the update button Your total should be 4
I am getting a 1 hehe
Do you see what i am saying?
thanks loads!
One
-
No!
OK, I had a complety different idea of what you were looking for. I thought you wanted the checkboxes added up and divided by the howmany field, ok I get it now.
-
No!
heh, my sig makes sence now
same page as last time, cleaned up the code too
PHP Code:
<?php
function getValue(){
$v = 0;
if(isset($_POST['one_dollar'])){
$v += $_POST['one_dollar'] * floor($_POST['howmany_one']);
}
if(isset($_POST['two_dollars'])){
$v += $_POST['two_dollars'] * floor($_POST['howmany_two']);
}
if(isset($_POST['four_dollars'])){
$v += $_POST['four_dollars'] * floor($_POST['howmany_four']);
}
if(isset($_POST['eight_dollars'])){
$v += $_POST['eight_dollars'] * floor($_POST['howmany_eight']);
}
if(isset($_POST['sixteen_dollars'])){
$v += $_POST['sixteen_dollars'] * floor($_POST['howmany_sixteen']);
}
echo $v;
}
?>
<html>
<head>
<title> Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="<? $_SERVER['PHP_SELF'] ?>">
<p>
<input type="checkbox" name="one_dollar" value="1" <?
if(isset($_POST['one_dollar']))
echo "checked";
?>>
$1 <input name="howmany_one" type="text" value="<?
if(isset($_POST['howmany_two']))
echo floor($_POST['howmany_one']);
else
echo '0';
?>"><br>
<input type="checkbox" name="two_dollars" value="2" <?
if(isset($_POST['two_dollars']))
echo "checked";
?>>
$2 <input name="howmany_two" type="text" value="<?
if(isset($_POST['howmany_two']))
echo floor($_POST['howmany_two']);
else
echo '0';
?>"><br>
<input type="checkbox" name="four_dollars" value="4" <?
if(isset($_POST['four_dollars']))
echo "checked";
?>>
$4 <input name="howmany_four" type="text" value="<?
if(isset($_POST['howmany_two']))
echo floor($_POST['howmany_four']);
else
echo '0';
?>"><br>
<input type="checkbox" name="eight_dollars" value="8" <?
if(isset($_POST['eight_dollars']))
echo "checked";
?>>
$8 <input name="howmany_eight" type="text" value="<?
if(isset($_POST['howmany_two']))
echo floor($_POST['howmany_eight']);
else
echo '0';
?>"><br>
<input type="checkbox" name="sixteen_dollars" value="16" <?
if(isset($_POST['sixteen_dollars']))
echo "checked";
?>>
$16 <input name="howmany_sixteen" type="text" value="<?
if(isset($_POST['howmany_two']))
echo floor($_POST['howmany_sixteen']);
else
echo '0';
?>"><br>
<input name="update" type="submit" value="Update">
</p>
<p>
<input name="total" type="text" readonly="true" id="total" size="16" maxlength="16" value="<? getValue(); ?>">
Total </p>
</form>
</body>
</html>
-
thats awesome
The only thing is i needed only one input for how many people
you have one after every option
can you make it to where you enter a number of people just in one place?
like a person would enter 5 people in the single how many box
then he checks some priced options
and hits update to get total price???
Right now you must enter 5 on every option to get total
thanks you code dude!
One
-
logo
what about this you like it?
this is a larg version the real one is just a little bigger than the one you have
-
No!
bleh, I'm out of it 'cause of the end of the semester. the thing you want to do is to change the line in the first PHP code from
[php] if($_POST['howmany'] > 0){
$v = $v / $_POST['howmany'];
}
[/php
to
PHP Code:
if(isset($_POST['howmany'])){
$v = $v * $_POST['howmany'];
}
That logo looks great! I wonder though, could I see it with the i's the same size as the other letters (I feel that they detract from the actually name of the site) and to include the element of '|', place one between bitwise and or, but at the same size you have there with everything centered horizontally
so, something like
BITWISE|OR
but centered. If that doesn't work out, then I think having all the letters the same size would be just fine.
I love the font and colors, very nice, it fits the site perfectly. I may have to use the blue color somewhere, I like how it goes with the grey
-
Yes I agree I thought the same thing it is hard to read with those in.
I will adjust it
glad you like the direction
I will try to edit the php
thanks I will post new logo here soon
One
-
I tried the php edit you gave me and I am lost as to what version and where the edit is
Do you have a moment to post the newest one up
with just one HOW MANY PEOPLE box.
so its like
checked "2.00" from list
type in how many people "3" into how many field
hit update
total should = "6.00"
thanks a lot!
one
-
how about this
(the color bar at bottom is for your use in keeping color scheme solid if you add more stuff to site)
-
No!
wow, nice job. And no, I haven't forgot about you
Here's a version that I think is correct *crosses fingers*
http://www.bitwiseor.com/updateVal.php
and the code is now commented in order to help your understanding. If you have any questions, please ask
PHP Code:
<?php
//------------------------------------------------------------
// getValue
//
// Retrieves the value of each checkbox contained in the _POST
// array. The value is summed for each one, then multiplied
// by the howmany textbox value and echoed
//------------------------------------------------------------
function getValue(){
// v holds the sum of checked checkbox values
$v = 0;
// we check that the variable is set before
// adding to ensure that the code works correctly
// on the first load and that the value exists.
//
// the var _POST[var_name] holds either the value specified
// or is not set, so no need to check when adding
if(isset($_POST['one_dollar'])){
$v += $_POST['one_dollar'];
}
if(isset($_POST['two_dollars'])){
$v += $_POST['two_dollars'];
}
if(isset($_POST['four_dollars'])){
$v += $_POST['four_dollars'];
}
if(isset($_POST['eight_dollars'])){
$v += $_POST['eight_dollars'];
}
if(isset($_POST['sixteen_dollars'])){
$v += $_POST['sixteen_dollars'];
}
// Check if howmany is set, then multiply the floor by the current value of v
if(isset($_POST['howmany'])){
// multiply by 100, take the floor and divide by 100
// to get dollar format
// ie. 1.33333333 -> 1.33
// floor can be changed to alter the affect of the code for
// more than 2 decimal places
//
// floor: round down
// ceil: round up
// round: normal rounding
$v = floor(100 * $v * floor($_POST['howmany'])) / 100;
}
// print the value
echo $v;
}
?>
<html>
<head>
<title>Update Value</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<!--
the form's action is to reload the page, so we use PHP_SELF
The method is POST, so the varisbles will be held in _POST[var_name]
every refresh
-->
<form name="form1" method="post" action="<? $_SERVER['PHP_SELF'] ?>">
<p>
<!--
each checkbox needs a name to identify it in _POST[ ] and a value that it will hold
When the var is set, we know that that the checkbox should be marked
In those cases print 'checked' to keep the same value as before
-->
<input type="checkbox" name="one_dollar" value="1" <? if(isset($_POST['one_dollar'])) echo "checked"; ?>>
$1<br>
<input type="checkbox" name="two_dollars" value="2" <? if(isset($_POST['two_dollars'])) echo "checked"; ?>>
$2<br>
<input type="checkbox" name="four_dollars" value="4" <? if(isset($_POST['four_dollars'])) echo "checked"; ?>>
$4<br>
<input type="checkbox" name="eight_dollars" value="8" <? if(isset($_POST['eight_dollars'])) echo "checked"; ?>>
$8<br>
<input type="checkbox" name="sixteen_dollars" value="16" <? if(isset($_POST['sixteen_dollars'])) echo "checked"; ?>>
$16<br>
<!--
if the var howmany is set, then we return the floor of it to keep howmany an integer. Remove
the floor( ) to allow non integer numbers. When it is not set, we set the default as 1
-->
<input name="howmany" type="text" size="16" maxlength="16" <? if(isset($_POST['howmany'])) {echo "value=\"".floor($_POST['howmany'])."\"";} else {echo "value=\"1\"";} ?>>
How Many<br>
<input name="update" type="submit" value="Update">
</p>
<p>
<!-- for the total, we call getValue to do our sum an dmultiplication -->
<input name="total" type="text" readonly="true" id="total" size="16" maxlength="16" value="<? getValue(); ?>">
Total
</p>
</form>
</body>
</html>
-
WOW THATS GREAT!!!!! YOU DID IT!!!!
thanks a lot my friend! I am happy
I will post a final vesion of the logo for you ASAP
now one more thing . . .
How easy is this to add more options as in ad a 100.00 check box and so on??? So I can add more items later.
happy!
One
-
No!
to add more items you need to do the following. In the html part you need a line like, where var is a unique name like sixteen_dollars, and value of var is the numerical value like 16.
PHP Code:
<input type="checkbox" name="[i][b][size=3]var[/size][/b][/i]" value="[i][b][size=3]value of var[/size][/b][/i]" <? if(isset($_POST['[i][b][size=3]var[/size][/b][/i]'])) echo "checked"; ?>> $[i][b][size=3]value of var[/size][/b][/i]<br>
then in the getValue function you need to add
PHP Code:
if(isset($_POST['[i][b][size=3]var[/size][/b][/i]'])){
$v += $_POST['[i][b][size=3]var[/size][/b][/i]'];
}
be sure to notice the single and double quotes around the variables and values
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|