Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes Multiple Select box Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Multiple Select box Problem" Watch "Multiple Select box Problem" New topic
Author

Multiple Select box Problem

mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Hai all,

I am developing an application which uses Jsp, Servlets, Javascript and Html. while developing the application the following problem occurs. i.e

BARCODE NAME COST QUANTITY TOTAL

The above all are select boxes. when we select the barcode the Name of the product of that barcode must be displayed in Name text box . For that I use javascript Onchange function. Which works fine for First row. But After Total I have another script that creates another row of text boxes. Here the actual problem starts. when I select the barcode of Second select box The OnChange function not working .
The entire code written in Jsp.

If any Solution I am very Thankful to You
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
How are you creating the new row? Are you attaching a new onchange handler?

Eric
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

yes by using onchange event i am creating multiple rows
Yoke Lee
Greenhorn

Joined: Mar 09, 2011
Posts: 3
maybe a lil bit piece of code will be helpful.

if it were me, i would use jquery and use each() function.
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

ok i dont have knowledge of jquery. It has to be in javascript or html or jsp
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You still have not showed code...

It is like a doctor performing surgery without the patient.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

raj legend wrote:ok i dont have knowledge of jquery. It has to be in javascript or html or jsp

jQuery is JavaScript. And it will help you do a lot of things much more easily. It is highly recommended.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

can you send me logic in jqery...
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

This is my code,



<HTML>
<HEAD>
<TITLE> Shopping </TITLE>
<SCRIPT language="javascript">
function addRow(tableID) {

var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var colCount = table.rows[0].cells.length;

for(var i=0; i<colCount; i++) {

var newcell = row.insertCell(i);

newcell.innerHTML = table.rows[0].cells[i].innerHTML;

switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}

}
}catch(e) {
alert(e);
}
}

</SCRIPT>
<script type="text/javascript">
function call()
{
alert("in call()");
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
for(var i=0;i<colCount;i++)
{
var bc=form.brcode[i].value;
alert("value of barcode="+bc[i]);
}

}
</script>
</HEAD>
<BODY>


<form name="form" id="form" action="testExample.jsp">
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD><INPUT type="text" name="brcode" onchange="call();"/></TD>
<TD><INPUT type="text" name="title" /></TD>
<TD><INPUT type="text" name="cost" /></TD>
<TD><INPUT type="text" name="quantity" /></TD>

<TD><INPUT type="text" name="quantity" onchange="addRow('dataTable')" /></TD>
</TR>
</TABLE>
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')"/>
</form>
</BODY>
</HTML>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Select box Problem
 
Similar Threads
Read Barcode value into a jsp text field
in dropdown problem
Dropdown List and Command button
onSubmit event on form
Populating subsequent select boxes with DWR