473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

checkboxes in javascript

i have many checkboxes and i can check as many as i want.
when i click submit i should see the products checked and calculate their total price.
this is my code:

Produit2.asp:
<%@LANGUAGE="VBSCRIPT"%>
<%
Set produitsXML =Server.CreateObject("Microsoft.XMLDOM")
produitsXML.load(Server.MapPath("Produit.xml"))
Set produits= produitsXML.documentElement
nbproduits=produits.childNodes.length
for j=0 to nbproduits-1
Set produit=produits.childNodes.item(j)
nump=produit.childNodes.item(0).text
nomp=produit.childNodes.item(1).text
prixp=produit.childNodes.item(2).text
%>
<html>
<head>
<Script LANGUAGE="JAVASCRIPT">
function memochoix(j){
document.formesaisie.choix.value=j;
}
</Script>
</head>
<body>
<table border='1'>
<tr><td><input type="checkbox" onClick=memochoix(<%=j%>)>
nom:<%=nomp%> prix:<%=prixp%>
</td>
</tr>
<%next%>
</table>
<form name="formesaisie" action="chercherProduit.asp" method=post>
<input type="hidden" name="choix">

<input type="submit">
</form>
</body>
</html>


chercherProduit.asp:
<%@LANGUAGE="VBSCRIPT"%>
<%vchoix=Request.form("choix")
Set produitsXML=Server.CreateObject("Microsoft.XMLDOM" )
produitsXML.load(Server.MapPath("Produit.xml"))
Set produits=produitsXML.documentElement
Set produit=produits.childNodes.item(vchoix)
nump=produit.childNodes.item(0).text
nomp=produit.childNodes.item(1).text
prixp=produit.childNodes.item(2).text
%>
<html>
<body>le produit choisi est:<%=nump%> nom:<%=nomp%> prix:<%=prixp%>
</body>
</html>

Produit.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
<?stylesheet type="text/xsl" href="Produit.xsl"?>
<!DOCTYPE produits [
<!ELEMENT produits (produit*)>
<!ELEMENT produit (nump,nomp,prixp)>
<!ELEMENT nump (#PCDATA)>
<!ELEMENT nomp (#PCDATA)>
<!ELEMENT prixp (#PCDATA)>
]>
<produits>
<produit>
<nump>key</nump>
<nomp>keyboard</nomp>
<prixp>20</prixp>
</produit>
<produit>
<nump>scr</nump>
<nomp>screen</nomp>
<prixp>80</prixp>
</produit>
<produit>
<nump>web</nump>
<nomp>webcam</nomp>
<prixp>40</prixp>
</produit>
<produit>
<nump>usb</nump>
<nomp>usb</nomp>
<prixp>30</prixp>
</produit>
<produit>
<nump>rou</nump>
<nomp>router</nomp>
<prixp>60</prixp>
</produit>
<produit>
<nump>mou</nump>
<nomp>mouse</nomp>
<prixp>15</prixp>
</produit>
<produit>
<nump>spe</nump>
<nomp>speaker</nomp>
<prixp>30</prixp>
</produit>
</produits>



the problem is that i just can see the product of the last checkbox checked when i click submit, but what i want is to see all products chosen and to calculate their total price.
thank u.

--------------------------------------------------------------------------------
May 4 '07 #1
1 1274
acoder
16,027 Expert Mod 8TB
There's a problem in your ASP. If you look at the generated source, you'll probably see multiple html, body and form tags as well as the same javascript repeated multiple times.

You need to move the for loop further down to avoid the repetition. The reason why you get only the last checkbox is that you have multiple input hidden that is overwritten. You need to add to it - not overwrite it. Add using, e.g.
Expand|Select|Wrap|Line Numbers
  1. obj.value+=","+val
Then in your ASP, loop through the list separated by commas.
May 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul Rubin | last post by:
Hi all. I'm wondering if there's a way to have checkboxes become selected without clicking the mouse. Perhaps if you rollover the checkboxes, they could toggle checked and unchecked? Or perhaps you...
9
by: Gary | last post by:
Hello, Is it possible to dynamically update a textbox with words chosen from a list using form checkboxes and javascript? Gary
5
by: Dave D. | last post by:
I have a total of 8 checkboxes, but the user is only allowed to check any three of them. After have been checked I have an alert box saying that only 3 boxes can be checked. I'm trying to get so...
6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
3
sunbin
by: sunbin | last post by:
Hi, I am having in a Trouble when working with dynamic checkboxes (i.e. checkboxes with the same name, e.g. <input type="checkbox" name = "check" value="dynamic integer value">) I have...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
13
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.