Hello every one.
I am stuck in a place. I am entring medicine record in a table. That's most possible that medicine may exceeds from the rows i am providing. I would like to be assist how can i add new new with a hyperlink text. Also how this row will be added to a php insert script. so faar i have just designed the front.end page.

Please see the attachement of .png file of that page in browser here with this article so that you might get a bit clear idea what i mean.

Regards.
Aamir Karim.

Hi Aamir Karim,
I'm still not clear, is't the Medicine table will fill up with the data and to be stored in database when Submit button clicked ? And if the row of the table not enough, then you want to click the link below to add the another row right ?
If you say so, maybe you can use the Ajax to call the another php file to create the another row below.

Correct me if my idea were not suitable..

To add a row at the end of the HTML table you can use Javascript and insertRow() and insertCell() methods. Create a function that will insert a row and four cells in that new row. Then make a link with an onclick event that will trigger inserting of the row. See example here.

To save the data in database use either Ajax as diprofinfiniti suggested or just process the form by submitting it usual way.

Thanks @diprofinfiniti and broj1
Diprofinfiniti. You are getting my point corrent. That's what I need. Someone told me that you can use array which may store n numbers of rows you need. Kindly give me example for aaray in php. Thanks again.

I hvae studied the code and applied. Its working fine but I need that new row and cells should be inserted at the end of the table but it is appearing on the top row of the table above other rows. Please help me where should i make changes that the new row should appear below to the other rows?

<script>
function displayResult()
{
var table=document.getElementById("myTable");
var row=table.insertRow(0);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
cell1.innerHTML="New";
cell2.innerHTML="New";
}
</script>
</head>
<body>

<table id="myTable" border="1">
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<br>
<button type="button" onclick="displayResult()">Insert new row</button>

Regards,

Thanks. Its working. Just changed the index of row on line 5 from "0" to "my required number"

E.g:

var row=table.insertRow(5);

There are already 5 rows in my table. So if i have to enter an additional row. It'l be on 6th number. And we know that these indexd number in any computer language starts from 0, that's why i took 5 in braces when i need a row on 6th number.

Thanks ALOt.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.