jquery - Add, edit and delete function to my javascript -


i'm looking add edit , delete functionality following javascript , i'm not sure start.

this functions fine input add needs editable , deletable. javascript way go here?

html

<table width="600px" class="setpoint-form-table">         <tr>             <td colspan="5">                 <p style="font-size:16px; float:left;">first name / last name table post , edit</p>              </td>         </tr>         <tr>             <td colspan="5" height="20px"></td>         </tr>         <tr>              <input type="text" id="rowplaceholder2" style="visibility:hidden;" />             <td width="100px" style="font-size:14px">first name</td>             <td><input type="text" id="fname" class="setpoint-textbox" /></td>             <td width="100px" style="font-size:14px;">last name</td>             <td><input type="text" id="lname" class="setpoint-textbox" /></td>             <td><button type="button" id="edit">edit</button></td>           </tr>         <tr>             <td colspan="5" height="20px"></td>         </tr>         <tr>             <td colspan="5"><button type="button" onclick="hvacstandards()">submit</button></td>         </tr>         <tr>             <td colspan="5">                 <br />                 <br />                   <table width="600px" id="testingwithedit">                     <tr>                         <td style="background-color:#fff; color:#00468c; border-bottom:1px solid #000; border-right:1px solid #000;">first name</td>                         <td style="background-color:#fff; color:#00468c; border-bottom:1px solid #000;">last name</td>                     </tr>                 </table>               </td>         </tr>     </table> 




javascript

function hvacstandards() {   var rowid = document.getelementbyid("rowplaceholder2").value;   var firstname = document.getelementbyid("fname").value;   var lastname = document.getelementbyid("lname").value;   var shtml = "<tr>" +             "<td id=\"firstname" + rowid + "\">" + firstname + "</td>" +             "<td id=\"lastname" + rowid + "\">" + lastname + "</td>" +             "</tr>";   $("#testingwithedit").append(shtml);   rowid++;   document.getelementbyid("rowplaceholder2").value = rowid;   document.getelementbyid("fname").value = "";   document.getelementbyid("lname").value = ""; } 

here's 1 of many ways this:

in fiddle, added column shtml containing edit , delete buttons call editrow() , deleterow() respectively, both passing parameter of rowid.

defined 2 new global variables, newrow , currentrow. modified hvacstandards use newrow rowid. additionally, modified switch saveedits if currentrow not -1, hitting submit button saves edits instead of creating new row.

then created the editrow function fills textboxes html contained within firstname+rowid , lastname+rowid, , set currentrow rowid.

the saveedits function modifies html of table rows new values inputs, clears inputs, , resets currentrow -1 hitting submit add new row next time.

finally, deleterow function removes row dom. (i added id tr in shtml row whole can identified).

let me know if makes sense , need :)


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -