Java Script
hi,
im having a problem in updating the cart. below is the code for that.
what i want is i need to enter the how much quantity by entering in the textbox and when i click on the update cart i need to display the total amout (i.e multiply the quantity with the amount) at the palce of lable.
plz help me..
thanx in advance.
<%@ page language="java" import="java.sql.*,java.io.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Gallery Page </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
window.onload=function ()
{
var now=new Date();
document.forms[document.forms.length-1].rcf_date.value = now;//.toGMTString();
}
function call_1(id)
{
window.location.replace("./DcartServlet?id="+id);
}
function Value(amount) {
var d = document;
var val = d.getElementById('text1');//quantity
//alert(n);
var lab = d.getElementById('amt');
//var b=Integer.parseInt(amount);
var a=amount*val.value;
//alert(a);
lab.innerHTML = a;
}
</script>
</HEAD>
<form name="f1">
<BODY>
<table border=0>
<tr><td><img src="./images/Untitled-30.jpg" width="680" height="170"></td>
<td><table border=0>
<tr><td align="right"><a href="user_login.html" style="text-decoration: none; border-bottom: 1px solid #FFFFFF">Login</a></td></tr>
<tr><td><img src="./images/cooltext75055321.gif" width="300" height="65"></td></tr>
<tr><td><img src="./images/images6.jpg" width="300" height="75"></td></tr></table>
</table>
<img src="./images/5.jpg" width="990" height="5"><br>
<table align="center" border=0>
<tr><td><a href="home.html" style="color: #FFFFFF"><img src="./images/home.png" height=40></a></td>
<td><a href="admin_login.html" style="color: #FFFFFF"><img src="./images/admin.png" height=40></td>
<td><a href="gallery.jsp" style="color: #FFFFFF"><img src="./images/gallery.png" height=40></td>
<td><a href="sitemap.html" style="color: #FFFFFF"><img src="./images/sitemap.png" height=40></td>
<td><a href="aboutus.html" style="color: #FFFFFF"><img src="./images/about us.png" height=40></td>
<td><a href="contactus.html" style="color: #FFFFFF"><img src="./images/contact us.png" height=40></td></tr>
</table >
<img src="./images/5.jpg" width="990" height="5"><br>
<table border=1>
<tr><td align="left">Wel-Come <B><I><font color="Orange">Guest </font></b></i></td>
<td>
<input type=text size="33" name="rcf_date">
<label name="new_date"></label>
</td><tr>
</table>
<table border=1>
<tr>
<td><table><tr> <td span=2 align="center"><b><font color="orange">Papular Category</font></b></td></tr><tr><td><img src="./images/flralfancy.jpg" width=75 height=50><img src="./images/Womens1.jpg" width=75 height=50></td><td> </td></tr>
<tr><td><img src="./images/trousers.jpg" width=75 height=50><img src="./images/SWeekend-Assortment.jpg" width=75 height=50></td><td></td></tr>
<tr><td span=2 align="right">More....</td></tr></table>
<table><tr> <td span=2 align="center"><b><font color="orange">Papular Brands</font></b></td></tr><tr><td><img src="./images/Nike_Shoes_Nz.jpg" width=75 height=50><img src="./images/nokia_n98.jpg" width=75 height=50></td><td> </td></tr>
<tr><td><img src="./images/Raymond.gif" width=75 height=50><img src="./images/Mayur.gif" width=75 height=50></td><td></td></tr>
<tr><td span=2 align="right">More....</td></tr></table>
<table><tr><td><img src="./images/verticalimg.gif"></td></tr></table>
</td>
<td>
<table border=1 width=658>
<tbody>
<td bgColor="#008080" width="47" align="center" height="19"><font color="#ffffff"><b>Sr No</b></font></td>
<td align="center" bgColor="#008080" width="107" height="19"><font color="#ffffff"><b>Product</b></font></td>
<td align="center" bgColor="#008080" width="224" height="19"><font color="#ffffff"><b>Price</b></font></td>
<td align="center" bgColor="#008080" width="270" height="19"><font color="#ffffff"><b>Quantity</b></font></td>
<td align="center" bgColor="#008080" width="270" height="19"><font color="#ffffff"><b>Amount</b></font></td>
<td align="center" bgColor="#008080" width="270" height="19"><font color="#ffffff"><b>Delete</b></font></td>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
int i=1;
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
PrintWriter pw=response.getWriter();
String id=request.getParameter("id");
try
{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shopping","root","password");
stmt=con.createStatement();
rst=stmt.executeQuery("select * from product where id='"+id+"'");
while(rst.next())
{
String m1=rst.getString(1);
String m2=rst.getString(2);
String m3=rst.getString(3);
String m4=rst.getString(4);
String m5=rst.getString(5);
String m6=rst.getString(6);
String m7=rst.getString(7);
String m8=rst.getString(8);
String m9=rst.getString(9);
int a=stmt.executeUpdate("insert into cart values('"+m1+"','"+m2+"','"+m3+"','"+m4+"','"+m5+"','"+m6+"','"+m7+"','"+m8+"','"+m9+"')");
}
rst=stmt.executeQuery("select * from cart");
while(rst.next())
{
if (i==(i/2)*2){
%>
<tr>
<td align="center" bgColor="#ffff98"><%=i%></td>
<td align="center" bgColor="#ffff98"><img src="./images/<%=rst.getString(9)%>" width="100" height="100"></td>
<td align="center" bgColor="#ffff98">$<%=rst.getString(7)%></td>
<td align="center" bgColor="#ffff98"><input id="text1" type="text" name="quan" value="1"> </td>
<td align="center" bgColor="#ffff98">$<label id="amt"><%=rst.getString(7)%></label> </td>
<td align="center" bgColor="#ffff98"><img src="./images/PNG-Symbol-Delete.png" width="25" height="25" onclick='call_1(<%=rst.getString(1)%>);'></td>
</tr>
<%
}
else{
%>
<tr>
<td align="center" bgColor="#ffcc68"><%=i%></td>
<td align="center" bgColor="#ffcc68"><img src="./images/<%=rst.getString(9)%>" width="100" height="100"></td>
<td align="center" bgColor="#ffcc68">$<%=rst.getString(7)%></td>
<td align="center" bgColor="#ffcc68"><input id="text1" type="text" name="quan" value="1"> </td>
<td align="center" bgColor="#ffcc68">$<label id="amt"><%=rst.getString(7)%></label> </td>
<td align="center" bgColor="#ffcc68"><img src="./images/PNG-Symbol-Delete.png" width="25" height="25" onclick='call_1(<%=rst.getString(1)%>);'></td> </tr>
<% }
i++;
}
rst.close();
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
%>
</table>
<table align="center">
<tr>
<td align="center"colspan=2><input type="button" value=" Update Cart "></td>
<td align="center"colspan=2><input type="button" value=" Check Out "></td>
<td align="center"colspan=2><a href="./home.html" style="color:#ffffff"><input type="button" value=" Continue shopping "></a></td>
</tr>
</table>
</td>
<td align="right"><img src="./images/verticalad.gif">
</td>
</tr>
</tbody>
</table>
</BODY>
</form>
</HTML>
View Answers
June 16, 2010 at 12:13 PM
Hi Friend,
1)Do modifications in your function Value(). Here it is:
function Value() {
var d = document;
var amount=document.getElementById('am');
var val = d.getElementById('text1');
var lab = d.getElementById('amt');
var a=Number(amount.value)*Number(val.value);
lab.innerHTML = a;
val.innerHTML=a;
}
2)Changed your table cell that consist of <label id="amt">.
<td align="center" bgColor="#ffcc68">$<input type="hidden" id="am" value="<%=rst.getString(7)%>"><label id="amt"><%=rst.getString(7)%></label> </td>
3)Call function Value() from the "Update Cart" button.
Thanks
Related Tutorials/Questions & Answers:
Java scriptJava script Source code for capturing the screen using
Java Script Advertisements
Java ScriptJava Script Hi,
Any one please share a code to swap the 2strings using
java script Java ScriptJava Script What is
Java Script? How to learn
Java Script?
Hi
Java Script is client side programming language. It runs on browser....
You can learn
Java Script from our JavaScript - JavaScript Tutorial pages
java scriptjava script how to write a
Java script program to enter number in two text fields and then automatically display the total in another text field
Java scriptJava script a
java script code for accept 10 numbers from the user and print in the
descending order without using sort method
java scriptjava script Hi,
Any one please tell me how, to store below elements in an array using
java script
12,13,14,a,b,xyz
Java Script.Java Script. Hi Sir,
The below
java script code is not working in Google chrome can yo give me the solution as soon as possible.
<
script type="text/javascript">
function setValue(){
var val="";
var frm
Java Script.Java Script. Hi Sir,
The below
java script code is not working in Google chrome can yo give me the solution as soon as possible.
<
script type="text/javascript">
function setValue(){
var val="";
var frm
Java Script.Java Script. Hi Sir,
The below
java script code is not working in Google chrome can yo give me the solution as soon as possible.
<
script type="text/javascript">
function setValue(){
var val="";
var frm
Java Script.Java Script. Hi Sir,
The below
java script code is not working in Google chrome can yo give me the solution as soon as possible.
<
script type="text/javascript">
function setValue(){
var val="";
var frm
Java ScriptJava Script Hello Sir, Is it possible to select only current date from datetimepicker in struts2 through
java script validation. Means when i select....
Try to send me
java script validation code for this purpose that user won't
Java Script.Java Script. The below code is nit working in Google chrome can any one tell me the solution as soon as possible.
<
script type="text/javascript">
<!--
function setValue(){
var val="";
var frm
Java Script.Java Script. Hi i want to submit two form using javascript.The below code submitting two forms in server but its not working in browser like chrome and firefox am struggling for many days give me solution as soon as possible
java scriptjava script how will you identify whether the number entered by the user has two digits or three digits.Assuming that the user enters only a three digit or two digit number.
<HTML>
<HEAD>
<
SCRIPT java scriptjava script write a
java script code which provide a menu for user which will enable him/her to either add or subtract or multiply or divide two numbers and produce the corresponding result.
<html>
<
java scriptjava script when you click a button how will you change the background color of a web page
java scriptjava script I want to display set of radio buttons after i select one option of the combobox
java scriptjava script what is the use of getElementById() method in jsp.
and give me its full knowledge with a example
java scriptjava script hi deepak, i have small doubt in the date ranges that when i select the date range then it display on the text boxes.
example:suppose i select the weekly date range then the dates are display on the text boxes up
Java ScriptJava Script I want to display an error message for the validation of email at the top of the page in red font i want to use
java scripts but i dont want to use alert box what i need to do
<html>
<script>
Java Script location.replace methodJava Script location.replace method Hi,
What does `Print `{<
SCRIPT LANGUAGE="JavaScript"> location.replace("} & urlpop & {","BOTTOM") </SCRIPT>}
this mean as this is written in an Lotus
Script agent and I
form to java script conversionform to
java script conversion I am using a form one more form cotain a piece of code .
how to convert it to
java script to function it properly..." name="ie" value="UTF-8" />
<input type="text" name="
q" size="55" />
java script - Development processjava script how could i devlop code for create widget. i need to generate
java script that if paste to any other web site will generate the widget. a widget can contain image text video or combination
qunit jquery with java scriptqunit jquery with
java script hi deepak
How to write a javascript code and do the test by using qunit sample application
and as I am new to testing how to setup the environment for
java script testing? where should I run
java script - Ajaxjava script i know basic of
java script. i want to gain more knowledge in
java script. please send a link or guidelines to me. and ajax also
my mail address is
[email protected] Hi friend,
Javascript
script error - Java Beginnersscript error hi,
Is it possiple to use PHP function under the
script tag. plz help me. thank u in advance.
regards,
sakthi Hi Friend,
Yes It is possible to use PHP function under the
script Tag.
Thanks
java script - Ajaxjava script I have a
java script function and getting "pitems" list values in select, and i want to send the values in the form of List to my CommonService class. Below code is not working...
function f_getPop
Java script - Development processJava script Dear Sir/Mdm
I have a probem, when any user close the browser without logout at that moment the user should be logout, I wrote some
java script code for that its working in IE not Fire Fox, actually
java script - Development processjava script hi..
how to get previous and next buttons inside the table in the same page as like our mails in the inbox. Hi Friend,
Try the following code:
ID
Name
Address
Contact
Java Script HelpJava Script Help I have written a countdown timer using javascript... help ---
<html>
<head>
</head>
<
script language....'
window.location = 'crdtd.php?
q=b
script problem - Java Beginnersscript problem Even though both .js file and .jsp file present in the same location,
script is not working in mozilla but working in Internet... what i have written present in same location.
but the
script java script - Ajaxjava script I have a
java script function and getting "pitems" list values in select, and i want to send the values in the form of List to my CommonService class.
I want to display the selected value from the select box
java script - JSP-Servletjava script what is the use of hidden fields in
java script? if a page has 3 links the first link should be enabled and others should be disabled. once the form inside the first link is filled and submitted the next link should
java script and velidatores - Securityjava script and velidatores i made a job portal and in it many fields which required validate how i do throw
java script.. can you help me please send me common validate function which used in any site..... Hi
script code - Java Beginnersscript code hi,
thanks for ur fast reply. plzz, give me a sample code for PHP function under
script tag.
regards,
sakthi Hi friend,
Code to help in solving the problem :
Hello PHP World
Java Script ProgramJava Script Program <%--
Document : index
Created on : Oct 15, 2012, 9:21:34 PM
Author : SAMSUNG
--%>
<%@page... are available in the Sun
Java System Application Server 9.1 logs.
Sun
Java System
Java Script ProgramJava Script Program <%--
Document : index
Created on : Oct 15, 2012, 9:21:34 PM
Author : SAMSUNG
--%>
<%@page... are available in the Sun
Java System Application Server 9.1 logs.
Sun
Java System
java script codejava script code Hi Deepak,
Firstly wanna share the problem em facing:
working with servlet and jsp for my project. I have 3 main jsp pages which interacts with user for accepting user input and supply them
Sitemap Java Script Tutorial) In JavaScript |
Conditions In
Java Script |
Looping in JavaScript |
Functions... in JavaScript |
Email
validation is JSP using JavaScript |
Java
Script... Application With Ant and Deploying on
Jboss 3.0 |
J2EE Tutorial -
Java Bean
java script - JSP-Servletjava script add items How to add items in an array in JavaScript... in javascript</title><
script type="text/javascript" src="mtmcode.js"></script><
script type="text/javascript">
java script text boxjava script text box hi,
I created a button when i click on button(next/prev) new two textbox is created. i want to do the two textbox will show by next and prev button. when i click the next button only two textbox show
java script - Java Beginnersjava script how to get the variable value declared in javascript to the scriptlet of a jsp without using form Hi Friend,
Try it:
function hello(){
var myvar=document.getElementById("text").value
java script - Java Beginnersjava script hi sir,
the program code that i need for is :
1)there are two button in javascripting if you click the Ok button the cancel should disappear . Hi Friend,
Try the following code:
function
Merging of java script with servlet programMerging of
java script with servlet program how can we merge the
java script with the any servlet program for making web application intractive.Is there any program you have.\please help me to sove out this problem
java script - Java Beginnersjava script within a itself can i call a function into another function such like performing inner class or calling a method into other method and process it also Hi Friend,
Try the following code
java script - Development processjava script hi..
i need a table formate list of customers from the back end which will not more than 8 customers, the other customers in the backend can be viewed by next previous buttons into the same table.which is the same