Jump to content

Jangrina

Members
  • Posts

    20
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    Malaysia

Jangrina's Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. Did you really read the prob? The TOPIC is so much different, so, is the problem. The thread that was resolved was something about adding rows. And the topic resolved was "Problem with Add Row Dynamically". Can't you see the difference? But this thread is about Input Text. My input text cannot work. They cant receive input. If you don't want to help, don't say something like that.
  2. I don't understand your code. Its too difficult for me. But it works like a charm. Many thanks.
  3. i tried inp1.type = "text"; still cannot. I read somewhere type is optional. It will default to text when not specified. Not sure whether this fact is correct or not.
  4. Hi All, I created input text in a JavaScript function. When I try in browser, I cannot enter text into those fields. Can someone tell me why and how to solve this? HTML File In this file, a function crtTable() will be called to create rows, columns and input. <form id="frmDetails" name="form1"><table id="tblDetails" border="1"><tr> <td>YEAR</td> <td><input class="txtName" type="TEXT" name="year" id="year"></td> <td></td></tr><tr> <td>NAME 1</td> <td><input class="txtName" type="TEXT" name="name1" id="name1"></td> <td></td><tr><tr> <td>NAME 2</td> <td><input class="txtName" type="TEXT" name="name2" id="name2"></td> <td id="adder" onclick="addRow()">[+]</td></tr></table> <!--tblDetails--><br><input type="button" value="Create Table" onclick="crtTable()"></form><p id="pDetails"></p><table id="tblTax" border="1"><tbody id="btblTax" onclick="crtTable()"></tbody></table> <!--tblTax--> JavaScript All the input text created in below code, cannot be inserted with text. Pls help. // row 2 var tr2 = tbody.insertRow(-1); var td1 = tr2.insertCell(-1); td1.innerHTML = "Adjusted Income"; var td2 = tr2.insertCell(-1); var inp1 = document.createElement("input"); // input Adjusted Income 1 inp1.name = "inpAdjIncome1"; inp1.id = "inpAdjIncome1"; inp1.className = "txtCalc"; td2.appendChild(inp1); var td3 = tr2.insertCell(-1); var inp2 = document.createElement("input"); // input Adjusted Income 2 inp2.name = "AdjIncome2"; inp2.id = "AdjIncome2"; inp2.className = "txtCalc"; td3.appendChild(inp2); var td4 = tr2.insertCell(-1); td4.innerHTML = ""; var td5 = tr2.insertCell(-1); td5.innerHTML = ""; if (numOfName > 2) { for (i=3; i<=numOfName; i++) { td = tr2.insertCell(-1); td.innerHTML = ""; } } // row 3 var tr3 = tbody.insertRow(-1); var td1 = tr3.insertCell(-1); td1.innerHTML = "+ Balancing Charge"; var td2 = tr3.insertCell(-1); var inp1 = document.createElement("input"); // input Balancing Charge 1 inp1.name = "BalCharge1"; inp1.id = "BalCharge1"; inp1.className = "txtCalc"; td2.appendChild(inp1); var td3 = tr3.insertCell(-1); var inp2 = document.createElement("input"); // input Balancing Charge 2 inp2.name = "BalCharge2"; inp2.id = "BalCharge2"; inp2.className = "txtCalc"; td3.appendChild(inp2); var td4 = tr3.insertCell(-1); td4.innerHTML = ""; var td5 = tr3.insertCell(-1); td5.innerHTML = "";
  5. Hi All, Thank you for the feedback. With assistance, I have improved the code. But still the code have some glitch. Can you please look into this code. I have two files : 1. HTML In this file, call function addRow to add a row. <table id="tblDetails" border="1"><tr> <td>YEAR</td> <td><input class="txtName" type="TEXT" name="year" id="year"></td> <td></td></tr><tr> <td>NAME 1</td> <td><input class="txtName" type="TEXT" name="name1" id="name1"></td> <td></td><tr><tr> <td>NAME 2</td> <td><input class="txtName" type="TEXT" name="name2" id="name2"></td> <td id="adder" onclick="addRow()">[+]</td></tr></table> 2. JavaScript var numOfName = 2;function addRow( ){ ++numOfName; // change the current <td> back into an ordinary one with no content and no onclick hooked up this.id = null; this.innerHTML = ""; this.onclick = function() { /* do nothing */ }; // then add row to the entire table: var row = document.getElementById("tblDetails").insertRow(-1); // create col 1 var td1 = row.insertCell(-1); td1.innerHTML = "NAME " + numOfName; // create col 2 var td2 = row.insertCell(-1); var inp = document.createElement("input"); inp.name = "name" + numOfName; inp.id = "name" + numOfName; inp.className = "txtName"; td2.appendChild(inp); // create col 3 var td3 = row.insertCell(-1); td3.innerHTML = "[+]"; td3.id = "adder"; // this becomes the new adder td3.onclick = addRow;} The problem is when I first click "[+]", it adds a row, but it produces two "[+]". Pls refer attachment. How could this happen? What needs to be done in order to solve this?
  6. Hi all, I have two problems. My first problem is I want some symbols to act like a button. But it doesn't act one. E.g. When user click "[+]", it would trigger a java script function to add a row. I use span tag with mouse event onclick. I suppose the symbols "[+]" would be underlined but it doesn't. My code is as below: <html><head><title>ISI-Tac</title><script type="text/javascript" src="funIndex.js"></script><body><table id="DETAILS" border="1"><tr> <td>NAME 1</td> <td><input type="TEXT" name="name1" size="50"></td> <td></td><tr><tr> <td>NAME 2</td> <td><input type="TEXT" name="name2" size="50"></td> <td><span onclick="addRow('SHOW');">[+]</span></td><tbody id="ROW"><div id="SHOW"></div></tbody></tr></table></body></head></html> My second problem is my JavaScript function addRow is not functioning. Function addRow()is as below: function addRow(){ var tbody = document.getElementById("ROW"); //tbody = your table body tbody.innerHTML = ""; //empty table body tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = "NAME "; td = tr.insertCell(-1); td.innerHTML = "<input type="TEXT" name="name1" size="50">"; td = tr.insertCell(-1); td.innerHTML = "<span onclick="addRow()">[+]</span>";} Pls help me.
  7. Try to put a filter in for loop. If select option is 0, it will display all the data.I code like below. But all the data were not displayed at all. Why? <body ><p>Table of Contents</p>View by Track:<select id="TRACK" onchange="createRows()"> <option value="0">--Choose--</option> <option value="1">1-Islamic Finance</option> <option value="2">2-Accounting</option> <option value="3">3-Management & Marketing</option> <option value="4">4-Finance & Economic</option> <option value="5">5-Business</option></select></p><table border="1" > <tr> <th>Ref. No.</th><th>Track</th> <th>Title</th> </tr> <tbody id="CONTENT"><div id="SHOW"></div> <!--<script type="text/javascript"> createRows('SHOW');--></script> </tbody></table></body> function createRows() //to create rows using innerHTML{var tbody = document.getElementById("CONTENT"); //tbody = your table bodytbody.innerHTML = ""; //empty table body for (i=1; i<=73; i++) { if (document.getElementByID("TRACK").selectedIndex == 0 ) { tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = referenceNo(i); //ref. no td = tr.insertCell(-1); td.innerHTML = trackNo(i); //track td = tr.insertCell(-1); td.innerHTML = getTitle(i); //title and link } }}
  8. Can I create a new function? I want createRows does its function to display all the rows.
  9. Hi,I dont know how to code to display a certain rows dynamically depending on user's selection. The scenario is like this; when user select value 3, track that having value 3 will be displayed.My rows are created using innerHTML. I dont have idea how to work around with this code. Pls help. <body ><p>Table of Contents</p>View by Track:<select> <option value="0">--Choose--</option> <option value="1">1-XX</option> <option value="2">2-XX</option> <option value="3">3-XX</option> <option value="4">4-XX</option> <option value="5">5-XX</option> </select></p><table border="1" > <tr> <th>Ref. No.</th><th>Track</th> <th>Title</th> </tr> <tbody id="CONTENT"><div id="SHOW"></div> <script type="text/javascript"> createRows('SHOW');</script> </tbody></table></body> function createRows() //to create rows using innerHTML{var tbody = document.getElementById("CONTENT"); //tbody = your table bodytbody.innerHTML = ""; //empty table bodyfor (i=1; i<=73; i++) { tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = referenceNo(i); //ref. no td = tr.insertCell(-1); td.innerHTML = trackNo(i); //track td = tr.insertCell(-1); td.innerHTML = getTitle(i); //title and link}}
  10. Pls look into the code below.When run on browser, it cannot find the path.What is wrong? function createRows() //to create rows using innerHTML{ var tbody = document.getElementById("CONTENT"); //tbody = your table body tbody.innerHTML = ""; //empty table body for (i=1; i<=73; i++) { tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = referenceNo(i); //ref. no td = tr.insertCell(-1); td.innerHTML = trackNo(i); //track td = tr.insertCell(-1); td.innerHTML = getTitle(i); }}/** ----------------------------------------- TO RETURN TITLE -------------------------------------------------*/function getTitle(i){ var title = ""; switch(i) { case 1: title = "<a href=\"3-Management & Marketing\103.pdf\" target=\"_blank\">XXXXX</a>"; break; } return title;}
  11. The file is set according to the value of i. It is something like this. if i ==1 then href = "3-Management & Marketing\101.pdf"else if i == 2 then href = "1-Business\103.pdf"
  12. Hi, Below is my code.I am stuck in line shows below. function createRows() //to create rows using innerHTML{ var tbody = document.getElementById("CONTENT"); //tbody = your table body tbody.innerHTML = ""; //empty table body for (i=1; i<=73; i++) { tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = referenceNo(i); //ref. no td = tr.insertCell(-1); td.innerHTML = trackNo(i); //track td= tr.insertCell(-1); td.innerHTML = ; //I am stuck here }} I would like to have function call there where it will receive a value to link it to pdf file and also display the title. In HTML, I would be writing it like below. But, I want it to be dynamically set according to the value of i. <a href="3-Management & Marketing\103.pdf" target="_blank">XXXX</a> How to do this? Pls help.
  13. I wrongly type getElementId. It should be getElementByID.Do JavaScript have compiler/debugger? I used to use compiler like Visual C++ that shows the line no of the syntax error. Do JavaScript have something similar like this?
  14. I read thru internet if i use document.write, it will erase all the contents in the page after it is loaded. I am not so sure about my understanding about this. And, it is advisable to use innerHTML. I think this is what ur trying to explain. I am trying this below but still theres no display. Pls look into this and advise me whats need to be done with this code. My html code: <table border="1" > <tr> <th>Ref.1 No.</th><th>Track</th> <th>Title</th> </tr> <tbody id="CONTENT"><div id="SHOW"></div> <script type="text/javascript"> createRows('SHOW');</script> </tbody></table> My js code: function createRows(){var tbody = document.getElementId("CONTENT"); //tbody = your table bodytbody.innerHTML = ""; //empty table bodyfor (i=1; i<=10; i++){ tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = (100+i); td = tr.insertCell(-1); td.innerHTML = 3; td= tr.insertCell(-1); td.innerHTML = "Jangan bersedih";}}
×
×
  • Create New...