473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Insert data from a form into a table using JavaScript

hello, could anyone help me?
i am a beginer in java script and i want to put data from the form into a existing table and for every set of value fill in the text boxes of the form when these data are inserted in a table (but it doesn't work)a new row is inserted and in this rows are exported the data from form.
thank you in advance


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function formValidation()
  5. {
  6. var nrfacturaid = document.form1.nrfactura;
  7. var udatafactura = document.form1.datafactura;
  8. var tipfacturaid = document.form1.tipfactura;
  9. var valoarefacturaid = document.form1.valoarefactura;
  10. var uobservatii = document.form1.observatii;
  11. function nrfactura_validation(nrfacturaid)
  12. {
  13. var p=document.all["form1"]["nrfactura"].value.length;
  14. if (p==null || p=="")
  15.   {
  16.   alert("completeaza primul nume");
  17.   return false;
  18.   }
  19.  else if(p>20)
  20. {
  21. alert("nr maxim de caractere permise este 20");
  22. return false;
  23. }
  24. else("poti trece mai departe");
  25. {
  26. return true;
  27. }
  28. }
  29. //
  30. function insRow(nrfacturaid,udatafactura,tipfacturaid,valoarefacturaid,uobservatii)
  31. {
  32. insRow(nrfactura.value,datafactura.value,tipfactura.value,valoarefactura.value,observatii.value)
  33. var x=document.getElementById('myTable').insertRow(1);
  34. var y=x.insertCell(0);
  35. var z=x.insertCell(1);
  36. var k=x.insertCell(2);
  37. var l=x.insertCell(3);
  38. var m=x.insertCell(4);
  39. y.innerHTML="nrfactura";
  40. z.innerHTML="datafactura";
  41. k.innerHTML="tipfactura";
  42. l.innerHTML="valoarefactura"
  43. m.innerHTML="observatii"
  44. document.write("myTable").insRow(nrfactura.value);
  45. }
  46. }
  47. //
  48. </script>
  49. </head>
  50. <body> 
  51. <form name="form1" onsubmit="return formValidation()" >
  52. <tr>
  53. <td>nr factura </td>
  54. <td><input type="string" name="nr factura" size="12" /></td>
  55. </tr>
  56. </br>
  57. <tr>
  58. <td>data factura</td>
  59. <td><input type="text" name="data factura" size="40" /></td>
  60. </tr>
  61. </br>
  62. <tr>
  63. <td>tip factura</td>
  64. <td><select id="tip factura" name="tip factura">
  65. <option value="tip1"> tip1</option>
  66. <option value="tip2">tip2</option>
  67. <option value="tip3">tip3</option>
  68. </select></td>
  69. </tr>
  70. </br>
  71. <tr>
  72. <td>valoare factura</td>
  73. <td><input type="number" name="valoare factura" size="40"/></td>
  74. </tr>
  75. </br>
  76. <tr>
  77. <td>observatii<br>
  78. (optional)
  79. <td><textarea name="observatii" rows="10" cols="20"></textarea></td>
  80. </tr>
  81. </br>
  82. </br>
  83. <table id="myTable" border="2" onsubmit="return insRow(value)">
  84. <tr>
  85. <td>Nr factura</td>
  86. <td>Data</td>
  87. <td>tip factura</td>
  88. <td>valoare</td>
  89. <td>observatii</td>
  90. </tr>
  91. </table>
  92. <br />
  93. <input type="submit" value ="submit" onsubmit="insRow ()">
  94. </br>
  95. <tr>
  96. <td><input type="reset" name="reset" value="reset"/></td>
  97. <td>&nbsp;</td>
  98. </tr>
  99. </table>
  100. </form>
  101. </body>
Feb 10 '12 #1
1 7941
acoder
16,027 Expert Mod 8TB
It's quite difficult to follow the code without proper indentation.

Your insert function doesn't actually make use of the values in the form. It just sets the data to fixed values.

Also, check the error console. You have a number of errors in your code.
Feb 27 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lars Erik Hansen | last post by:
I want to write/insert the value of foundFiles into a table. How can i paste a value into a table using VB?? Can someone help? I want to get "FoundFiles(i)" and paste it into a table Set...
2
by: Max | last post by:
Hi, I have the following problem. I want to insert records into one table using the combination of two other tables. Here is a simplified example: Let's say the first table has a column with...
1
by: go2bee | last post by:
Tamplat is it HN: 49xxxxx Name : Cxxxx xxxxx PID : 3xxxxxxxxxxxx Address : 1xxx x xxxx , Tambonxxxx , Ampurxxxxxxx ,Provincexxxxx Postcode : 1xxxx At xxx is Data form Table Name
5
by: Hari2005 | last post by:
I try to get width of a table using javascript. Table width is not defined in table. It grows as per the data. Please suggest how to get table width using javascript at run time??????? Thanks in...
0
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the...
13
nabh4u
by: nabh4u | last post by:
hi, I am trying to insert multiple rows in a table using PL/SQL. I have two procedures and two tables. the first procedure gets the data from the source table, manipulates it and then sends the...
3
by: tokcy | last post by:
hi everyone, i am creating dynamic row in a table using javascript its working fine and now i want to create more than 1 table using javascript which is dynamic its also working fine but when i am...
2
by: pavelcc | last post by:
I need to insert data into a table after validating that the data doesn't already exist on the table. In addition to that I need to update data if there are any changes. I got the insert part...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.