Sorry for reviving this old thread. I am trying to add some data of the selected items in a a text field , but am not able to do that, as data from the first select keeps repeating. I dont have much knowledge of JavaScript. Will greatly appreciate any help.
Here is a sample of what I am trying to do with another script included:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#dataTable").live("change", function() {
$("[name^=price]").val($(this).find("option:selected").attr("data-price"));
})
});
</script>
<script type="text/javascript">
var clone;
function cloneRow(){
var rows=document.getElementById('dataTable').getElementsByTagName('tr');
var index=rows.length;
clone=rows[index-1].cloneNode(true);
var inputs=clone.getElementsByName('price'), inp, i=0 ;
while(inp=inputs[i++]){
inp.name=inp.name.replace(/\d/g,'')+(index+1);
}
}
function addRow(){
var tbo=document.getElementById('dataTable').getElementsByTagName('tbody')[0];
tbo.appendChild(clone);
cloneRow();
}
onload=cloneRow;
</script>
</head>
<body>
<form name="f1" action="" />
<input type="hidden" name="subject" value="Order" />
<input type="hidden" name="mail_options" value="NoEmpty" />
<table width="60%" border="1" cellspacing="1">
<tr>
<td width="25%"><b><font color="purple">Category A</b>
</font>
</td>
<td>
<table width="95%" border="1" cellpadding="1">
<thead>
<tr>
<th width="5%"></th>
<th width="10%">Qty.</th>
<th width="80%">Your Choice</th>
</tr>
</thead>
</table>
<TABLE id="dataTable" width="95%" border="1" cellspacing="1">
<tbody>
<TR>
<TD width="10%"><input type="text" name="cantEnt[]" size="2" maxlength="2" alt="Please enter quantity"
title="Please enter quantity" onKeyPress="return numbersonly(this, event)" /></TD>
<TD width="80%">
<select name="Ent[]">
<optgroup label="Cat A">
<option value=""></option>
<option value="A"data-price="1.00">First</option>
<option value="B"data-price="2.00">Second</option>
<option value="C"data-price="3.00">Third</option>
</optgroup>
</select>
</TD><td><input type="text" id="price" name="price" value="" readonly></td>
</TR>
</TBODY>
</TABLE>
<br>
<input type="button" value="Add a new row" onclick="addRow()">
<td align="center">
<BUTTON TYPE=SUBMIT style="color: brown;"><STRONG>Send It</STRONG></BUTTON></td>
</form>
</body>
</html>
Bookmarks