javascript - document.getElementById not working with dynamic id generation -


<!doctype html><!-- change license header, choose license headers in project properties. change template file, choose tools | templates , open template in editor. --><html><head><title>inventory master - material inwards</title>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width">     <link rel="stylesheet" href="inwards.css"/>     <link rel="stylesheet" href="bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css">     <link rel="stylesheet" href="bootstrap-3.3.2-dist/css/bootstrap.min.css" type="text/css"/>     <script src="jquery-2.1.3.min.js"></script>     <script src="inwards.js"></script> </head> <body>     <div id="operation">         <div class="container-fluid">             <div id="actbtngrp">                 <button class="actbtn">edit</button>                 <button class="actbtn">print</button>                 <button class="actbtn">delete</button>             </div>         </div>         <div class="container-fluid">             <div class="row">                 <div class="col-md-3" id="dh">date</div>                 <div class="col-md-3" id="dh">vendor name</div>             </div>             <div class="row">                 <div class="col-md-3"><input type="text" id="date" readonly></div>                 <div class="col-md-3"><input type="text" id="vendor" onkeydown="searchvendor(event)"></div>             </div>         </div>         &nbsp;         <div class="container-fluid">             <table id="input">                 <thead>                     <tr>                         <th>q</th>                         <th>level 1</th>                         <th>level 2</th>                         <th>product description</th>                         <th>$$</th>                         <th>qty.</th>                         <th>rate</th>                         <th>per</th>                         <th>uom</th>                         <th>$</th>                         <th>disc</th>                         <th>gorate</th>                         <th>amount</th>                     </tr>                 </thead>             </table>             &nbsp;             <div>             <button class="actbtn" id="add" onclick="addrow()">add record</button>             <button class="actbtn" id="save">save n move</button>             </div>         </div>     </div> </body> 

{ var q = 1;var o = "-";var id = 0;var iddata = $(":input").serializearray(); var currentid;var nextid;var previousid;var master = "tubemaster"; $(document).ready(function() { var today = new date(); var dd = today.getdate(); var mm = today.getmonth() + 1; var yyyy = today.getfullyear(); if (dd < 10) {     dd = '0' + dd; } if (mm < 10) {     mm = '0' + mm; } var today = dd + '/' + mm + '/' + yyyy; document.getelementbyid("date").value = today; var table = document.getelementbyid("input"); var row = document.createelement("tr"); row.setattribute("id", id); iddata[id] = id; table.appendchild(row); id++; (i = 0; < 1; i++) {     var td = document.createelement("td");     td.innerhtml = q;     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     q++;     id++; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.setattribute("contenteditable", "true");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++;     td.onkeydown = function(e) {         currentid = parseint(this.id);         if (e.keycode === 13) {             e.preventdefault();             nextid = currentid + 1;             document.getelementbyid(nextid).focus();         }         if (e.ctrlkey) {             if (e.keycode === 46) {                 tempid = currentid - 2;                 $('#' + tempid).remove();             }         }         if (e.keycode === 40) {             e.preventdefault();             nextid = currentid + 14;             document.getelementbyid(nextid).focus();         }         //write escape key function     }; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.setattribute("contenteditable", "true");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++;     td.onkeydown = function(e) {         currentid = parseint(this.id);         if (e.keycode === 13) {             e.preventdefault();             nextid = currentid + 3;             document.getelementbyid(nextid).focus();         }         if (e.keycode === 27) {             e.preventdefault();             previousid = currentid - 1;             document.getelementbyid(previousid).focus();         }         if (e.keycode === 40) {             e.preventdefault();             nextid = currentid + 14;             document.getelementbyid(nextid).focus();         }         if ((e.keycode !== 40) || (e.keycode !== 27) || (e.keycode !== 13)){             if (e.keycode === 13) {                 e.preventdefault();                 nextid = currentid + 3;                 document.getelementbyid(nextid).focus();             } else {                  var = parseint(this.id);                 var s = a.tostring();                 alert(a);                 alert(typeof a);                 alert(typeof s);                 var read = "hello";                 alert(read); 

problem here...... not getting value of var read after saying document.getelementbyid(s).value

                read = document.getelementbyid(s).value;                 alert(read);             }         }     }; } (i = 0; < 1; i++) {     var td = document.createelement("td");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++; } (i = 0; < 1; i++) {     var td = document.createelement("td");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.setattribute("contenteditable", "true");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++;     td.onkeydown = function(e) {         currentid = parseint(this.id);         if (e.keycode === 13) {             e.preventdefault();             nextid = currentid + 4;             document.getelementbyid(nextid).focus();         }         if (e.keycode === 27) {             e.preventdefault();             previousid = currentid - 3;             document.getelementbyid(previousid).focus();         }         if (e.keycode === 40) {             e.preventdefault();             nextid = currentid + 14;             document.getelementbyid(nextid).focus();         }     }; } (i = 0; < 1; i++) {     var td = document.createelement("td");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++; } (i = 0; < 1; i++) {     var td = document.createelement("td");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++; } (i = 0; < 1; i++) {     var td = document.createelement("td");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.innerhtml = o;     td.setattribute("contenteditable", "true");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++;     td.onkeydown = function(e) {         currentid = parseint(this.id);         if (e.keycode === 13) {             e.preventdefault();             nextid = currentid + 1;             document.getelementbyid(nextid).focus();         }         if (e.keycode === 27) {             e.preventdefault();             previousid = currentid - 4;             document.getelementbyid(previousid).focus();         }         if (e.keycode === 40) {             e.preventdefault();             nextid = currentid + 14;             document.getelementbyid(nextid).focus();         }     }; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.innerhtml = "";     td.setattribute("contenteditable", "true");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++;     td.onkeydown = function(e) {         currentid = parseint(this.id);         if (e.keycode === 13) {             e.preventdefault();             nextid = currentid + 1;             document.getelementbyid(nextid).focus();         }         if (e.keycode === 27) {             e.preventdefault();             previousid = currentid - 1;             document.getelementbyid(previousid).focus();         }         if (e.keycode === 40) {             e.preventdefault();             nextid = currentid + 14;             document.getelementbyid(nextid).focus();         }     }; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.innerhtml = "";     td.setattribute("contenteditable", "true");     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++;     td.onkeydown = function(e) {         currentid = parseint(this.id);         if (e.keycode === 13) {             e.preventdefault();             document.getelementbyid("add").focus();         }         if (e.keycode === 27) {             e.preventdefault();             previousid = currentid - 1;             document.getelementbyid(previousid).focus();         }         if (e.keycode === 40) {             e.preventdefault();             nextid = currentid + 14;             document.getelementbyid(nextid).focus();         }     }; } (i = 0; < 1; i++) {     var td = document.createelement("td");     td.innerhtml = "";     row.appendchild(td);     td.setattribute("id", id);     iddata[id] = id;     id++; } document.getelementbyid("vendor").focus();}); 

basically generating runtime id , while entering user input want read not able read neither "this.id" nor putting "3". 3 dynamically runtime generated id.

plz help.....

/*     document.getelementbyid("date").value = today;   -- doesn't exist far can see. maybe remove quotes or use var today? 

the global var read

    read = document.getelementbyid(s).value;  // global var     alert(read); 

which var read? global var read or local var read ("hello") defined repeatedly in loop?

    if ((e.keycode !== 40) || (e.keycode !== 27) || (e.keycode !== 13)){     ....var read = "hello";     } */ 

document.getelementbyid("hello") undefined.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -