<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>DOM form elements</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> var rowCount = 0; function appendtable(){ // get html elements var divElement = document.getElementById("divide"); // create a new table each time. var tableElement = document.createElement("table"); // create new row and cells var newTr = document.createElement("tr"); var td0 = document.createElement("td"); var td1 = document.createElement("td"); var td2 = document.createElement("td"); var td3 = document.createElement("td"); // create new select var oSelect = document.createElement("select"); // set onchange event for select box oSelect.setAttribute("onchange", "txtChange(this);"); // keep track of the id of the object for interest. oSelect.setAttribute("id", "txtchange" + rowCount++); // create and add new option 0 var oOption0 = document.createElement("OPTION"); var t0 = document.createTextNode("Ferrari"); oOption0.setAttribute("value", 4); oOption0.appendChild(t0); oSelect.appendChild(oOption0); // create and add new option 1 var oOption1 = document.createElement("OPTION"); var t1 = document.createTextNode("Fessari"); oOption1.setAttribute("value", 3); oOption1.appendChild(t1); oSelect.appendChild(oOption1); // cretae text elements var txt1 = document.createElement("input"); txt1.type="text"; txt1.value="mamu"; var txt2=document.createElement("input"); txt2.type="text"; txt2.value="Machan"; var txt3=document.createElement("input"); txt3.type="text"; txt3.value="maplai"; // add content to the table. td0.appendChild(oSelect); td1.appendChild(txt1); td2.appendChild(txt2); td3.appendChild(txt3); newTr.appendChild(td0); newTr.appendChild(td1); newTr.appendChild(td2); newTr.appendChild(td3); tableElement.appendChild(newTr); divElement.appendChild(tableElement); // only need to do this ugly hack for Internet Explorer.... don't know why. never had to do this with dynamic nodes before // must be some bug i have missed. if(window.event) { document.getElementById("divide").innerHTML = document.getElementById("divide").innerHTML; } } // function requires a node object. function txtChange(noden) { alert("hi: '" + (noden?noden.id:"node is null") + "'"); var di = document.getElementsByTagName("select"); //when i tried to get the selected value its showing error. // tag name function returns a node list.. not a single node.. so if only one, // then access using di.item(0) // however using my code changes, there is no reason to establish the node here, as it is // being passed in as a parameter. } </script> <style type="text/css"> <!-- /* cascading style sheet */ body { font-family:verdana; } --> </style> </head> <body> <div id="divide"> <input type="button" onclick="appendtable()" value="Press me"> </div> </body> </html>
<html> <head> <title> working with jscript</title> <script type="text/javascript"> <!-- function appendtable(){ var parent = document.getElementById("divide"); var div = document.createElement("div"); var tbl = div.appendChild(document.createElement("table")); var tb = tbl.appendChild(document.createElement("tbody")); var tr = tb.appendChild(document.createElement("tr")); var td = tr.appendChild(document.createElement("td")); parent.appendChild(div); var oSelect=document.createElement("select"); var oOption = document.createElement("option"); var t0 = document.createTextNode("Ferrari"); oOption.setAttribute("value", 0); oOption.appendChild(t0); oSelect.appendChild(oOption); var oOption1 = document.createElement("option"); var t1 = document.createTextNode("Fessari"); oOption1.setAttribute("value", 1); oOption1.appendChild(t1); oSelect.appendChild(oOption1); oSelect.onchange=function(){ txtChange(this); } var pname=document.createElement("input"); pname.type="text"; pname.value="product name" pname.name = "pname"; var price=document.createElement("input"); price.type="text"; price.value="product price" var qty=document.createElement("input"); qty.type="text"; qty.value="product quantity" var sku=document.createElement("input"); sku.type="text"; sku.value="product SKU" var upc=document.createElement("input"); upc.type="text"; upc.value="product UPC" td.appendChild(oSelect); td.appendChild(pname); td.appendChild(price); td.appendChild(qty); td.appendChild(sku); td.appendChild(upc); } // get element with name from parent node... function elementOfName(parentNode, name){ var nodeList = parentNode.getElementsByTagName("INPUT"); for(var i=0; i<nodeList.length; i++){ if(nodeList.item(i).name == name){ return nodeList.item(i); } } return null; } function txtChange(obj){ var pname = elementOfName(obj.parentNode, "pname"); if(pname) alert(pname.value); alert(obj.selectedIndex+" "+obj[obj.selectedIndex].text) var elt=obj[obj.selectedIndex].text; // set values of hidden elements here: elementOfName(document, "pId").value = elt.value; // ... etc } --> </script> </head> <body bgcolor=white> <FORM ACTION=DList.html METHOD=POST> Purchase Order ID <input type="text" name="poId"><br> Sendor Address <input type="text" name="senderAddress"><br> Vendor Address <input type="text" name="vendorAddress"><br> poStatus <input type="text" name="poStatus"><br> poDate <input type="text" name="poDate"><br> expDate <input type="text" name="expDate"><br><br> <h4> Product Details</h4> <input type="button" onclick="appendtable()" value="Add Product"> <div id="divide"></div> <input type="hidden" name=pId value=elt> <input type="hidden" name=pName> <input type="hidden" name=price> <input type="hidden" name=pQty value=qty.value> <input type="hidden" name=SKU value=sku.value> <input type="hidden" name=UPC value=upc.value> <br> <input type="submit" name="btnSubmit" value="Submit Order"> </form> </body> </html>
<html> <head> <title> working with jscript</title> <script type="text/javascript"> function appendtable() { var parent = document.getElementById("divide"); var div = document.createElement("div"); var tbl = div.appendChild(document.createElement("table")); var tb = tbl.appendChild(document.createElement("tbody")); var tr = tb.appendChild(document.createElement("tr")); var td = tr.appendChild(document.createElement("td")); parent.appendChild(div); var oSelect=document.createElement("select"); var oOption = document.createElement("option"); var t0 = document.createTextNode("Ferrari"); oOption.setAttribute("value", 0); oOption.appendChild(t0); oSelect.appendChild(oOption); var oOption1 = document.createElement("option"); var t1 = document.createTextNode("Fessari"); oOption1.setAttribute("value", 1); oOption1.appendChild(t1); oSelect.appendChild(oOption1); var pname=document.createElement("input"); pname.type="text"; pname.value="product name" pname.name = "pname"; var price=document.createElement("input"); price.type="text"; price.value="product price" var qty=document.createElement("input"); qty.type="text"; qty.value="product quantity" var sku=document.createElement("input"); sku.type="text"; sku.value="product SKU" var upc=document.createElement("input"); upc.type="text"; upc.value="product UPC" td.appendChild(oSelect); td.appendChild(pname); td.appendChild(price); td.appendChild(qty); td.appendChild(sku); td.appendChild(upc); oSelect.onchange=function(){ txtChange(this,pname,price,qty,sku,upc); } } // get element with name from parent node... function elementOfName(parentNode, name){ var nodeList = parentNode.getElementsByTagName("INPUT"); for(var i=0; i<nodeList.length; i++){ if(nodeList.item(i).name == name){ return nodeList.item(i); } } return null; } function txtChange(obj,pname,price,qty,sku,upc){ var pname = elementOfName(obj.parentNode, "pname"); //var price = elementOfName(obj.parentNode, "price"); var pQty = elementOfName(obj.parentNode, "qty"); var SKU = elementOfName(obj.parentNode, "price"); var UPC = elementOfName(obj.parentNode, "qty");// this is not working i dont know why.... } </script> </head> <body bgcolor=white> <FORM ACTION=dlist.html METHOD=POST> Purchase Order ID <input type="text" name="poId"><br> Sendor Address <input type="text" name="senderAddress"><br> Vendor Address <input type="text" name="vendorAddress"><br> poStatus <input type="text" name="poStatus"><br> poDate <input type="text" name="poDate"><br> expDate <input type="text" name="expDate"><br><br> <h4> Product Details</h4> <input type="button" onclick="appendtable()" value="Add Product"> <div id="divide"></div> <input type="hidden" name=pId>//here i m sending eachand every product to submitted into the next page <input type="hidden" name=pName> <input type="hidden" name=price> <input type="hidden" name=pQty> <input type="hidden" name=SKU> <input type="hidden" name=UPC> <br> <input type="submit" name="btnSubmit" value="Submit Order"> </form> </body> </html>
<html> <head> <title> working with jscript</title> <script type="text/javascript"> function appendtable() { var parent = document.getElementById("divide"); var div = document.createElement("div"); var tbl = div.appendChild(document.createElement("table")); var tb = tbl.appendChild(document.createElement("tbody")); var tr = tb.appendChild(document.createElement("tr")); var td = tr.appendChild(document.createElement("td")); parent.appendChild(div); var oSelect=document.createElement("select"); var oOption = document.createElement("option"); var t0 = document.createTextNode("Ferrari"); oOption.setAttribute("value", 0); oOption.appendChild(t0); oSelect.appendChild(oOption); var oOption1 = document.createElement("option"); var t1 = document.createTextNode("Fessari"); oOption1.setAttribute("value", 1); oOption1.appendChild(t1); oSelect.appendChild(oOption1); oSelect.onchange=function(){ txtChange(this); } var prodname=document.createElement("input"); prodname.type="text"; prodname.value="product name"; prodname.name = "prname"; var prodprice=document.createElement("input"); prodprice.type="text"; prodprice.value="product price"; prodprice.name="prprice"; var prodqty=document.createElement("input"); prodqty.type="text"; prodqty.value="product quantity"; prodqty.name="prqty"; var prodsku=document.createElement("input"); prodsku.type="text"; prodsku.value="product SKU"; prodsku.name="prsku"; var produpc=document.createElement("input"); produpc.type="text"; produpc.value="product UPC"; produpc.name="prupc"; td.appendChild(oSelect); td.appendChild(prodname); td.appendChild(prodprice); td.appendChild(prodqty); td.appendChild(prodsku); td.appendChild(produpc); } function elementOfName(parentNode, name) { var nodeList = parentNode.getElementsByTagName("INPUT"); for(var i=0; i<nodeList.length; i++) { if(nodeList.item(i).name == name) { return nodeList.item(i); } } return null; } function txtChange(obj) { var pName = elementOfName(obj.parentNode, "prname"); var tprice = elementOfName(obj.parentNode, "prprice"); var tqty = elementOfName(obj.parentNode, "prqty"); var tsku = elementOfName(obj.parentNode, "prsku"); var tupc = elementOfName(obj.parentNode, "prupc"); var elt=obj[obj.selectedIndex].text; } </script> </head> <body bgcolor=white> <%@ taglib uri="http://webm-taglib.tld" prefix="webm" %> <FORM ACTION=http://10.200.13.83:5555/invoke/app/flowDList METHOD=POST> Purchase Order ID <input type="text" name="poId"><br> Sendor Address <input type="text" name="senderAddress"><br> Vendor Address <input type="text" name="vendorAddress"><br> poStatus <input type="text" name="poStatus"><br> poDate <input type="text" name="poDate"><br> expDate <input type="text" name="expDate"><br><br> <h4> Product Details</h4> <input type="button" onclick="appendtable()" value="Add Product"> <div id="divide"></div> <input type="hidden" name=pId> <input type="hidden" name=pName> <input type="hidden" name=price> <input type="hidden" name=pQty > <input type="hidden" name=SKU > <input type="hidden" name=UPC > <br> <input type="submit" name="btnSubmit" value="Submit Order"> </form> </body> </html>
elementOfName(document, "pName").value = elementOfName(obj.parentNode, "prname").value;
<input type="hidden" name='pName' id="pName">
document.getElementById("pName").value = elementOfName(obj.parentNode, "prname").value;
| DaniWeb Message | |
| Cancel Changes | |