Jump to content

please help with this(javascript & php)


r-it

Recommended Posts

can anyone help me with this, please hav a look at the image in the link below to view what i'm trying to do. i'm doing this webapp in php, and this is what it should do: a person selects a quantity and without refreshing the page, and gives the total on the totals field. so from the dropdown, when they select a different quantity, 3 for example, it must multiply 3 by the price and give the total for every change, like if they select a quantity and then they choose to select a new one, the dropdown must handle this. I initially wanted a list box,like you have in vb so that a eron can just click the down or up arrow to select the quantity but i dunno how this is done in plain html, my editor doesnt have that. please, any help is welcome, urls whatever http://img145.imageshack.us/my.php?image=itemswf0.jpg
Link to comment
Share on other sites

  • 2 weeks later...
Hmmm... I would have an onChange event in the drop down box, that would activate a function that would then fill teh other values (price, quantity) with the right values based on the new selection.  I'm not fluent enough to do that off the top of ny head, but that would work :P
Link to comment
Share on other sites

It's sloppy, but it should get you started.

[code]<style type="text/css">
img { border-style:none; }
</style>

<script type="text/javascript">
function readd(i) {
f=document.forms['myform'];
f.elements['total'+i].value = f.elements['price'+i].value * f.elements['quantity'+i].value;
}
function upme(i) {
f=document.forms['myform'].elements['quantity'+i];
f.value = (f.value * 1) + 1;
readd(i);
}
function downme(i) {
f=document.forms['myform'].elements['quantity'+i];
if(f.value>0) {
f.value = (f.value * 1) - 1;
readd(i);
}
}
</script>
</head>
<body>
<form name="myform" action="checkboxes.asp" method="post">
<input type="text" name="nailgun" value="nailgun" readonly="readonly" />
<input type="text" value="199" name="price1" readonly="readonly" />
<input type="text" value="0" name="quantity1" readonly="readonly" />
<a href="#" onClick="upme(1); return false;"><img src="up.gif" alt="up" /></a>
<a href="#" onClick="downme(1); return false;"><img src="down.gif" alt="down" /></a>
<input type="text" name="total1" value="0" readonly="readonly" />
</form>
</body>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.