javascript add,edit remove in jsp page

hi experts,

I have some problem with javascript in my jsp page

I have three fields

<span class="formleft">LRN# <input type="text" name="lrnNo" size="20" value='<%= field1[i]%>' class="formstyle">  </span>

 <span class="formleft">Lab Test <input name="labTestDesc" type="text" class="formstyle" value='<%= field2[i]%>' size="20">  </span>

<span class="formleft">Lab Result <input name="labResultDesc" type="text" class="formstyle" value='<%= field3[i]%>' size="20">  </span>

the above three fields are getting values FROM DATABASE and getting displayed in one row. Now , i have three buttons under these three fields
 <input name="Submit1" type="button" class="formbutton" value="Add " onclick="addLRN();">
 <input name="Submit2" type="button" class="formbutton" value="Edit " onclick="editLRN();">
 <input name="Submit3" type="button" class="formbutton" value="Remove" onclick="removeLRN();">

my requirment:
the three buttons should  add(new row with three blank fields) , edit(current row fields) and delete(current row fields) respectively.
any idea how i can add a blank row with the above three fields ? any logic for edit and remove would be greatly appreciated.

thanks
J

LVL 10
jaggernatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
mvan01Commented:
Hi jaggernat,

What html tag(s) appear after the  Lab Result  line?

<span class="formleft"></span>

Or something else?  Are you limited by other existing html constructs around this, or are these the only requirements?

Do you have any existing code for the required functions?

function addLRN() {
...
}

function editLRN() {
...
}

function removeLRN() {
...
}

Posting these would help the experts.

Peace and joy.  mvan
0
 
mvan01Commented:
Ok, here's a start.  Added reference in the call.  Added two identical rows.  Created the delete function.  There's more to do.

Peace and joy.  mvan


<script language="JavaScript">

function addLRN(anObj) {
// more challenging than the rest
}

function lockLRN() {
  // to be run onLoad;
  // step through all document elements, locking all text fields w/in 'labels' DIVs
}

function editLRN(anObj) {
  // for testing
  alert(anObj.name);
  alert(anObj.id);      // id returns labels - ID of the div
  alert(anObj.value);

  // unlock three text boxes on this row for editing

  // edit will look something like this ??
  anObj.focus(lrnNo);
  // and this ??  Neither work, both required w/ correct syntax
  anObj.lrnNo.select();
}

function removeLRN(anObj) {
  var ans = confirm('Are you sure you want to delete this row?');
  if (ans) anObj.parentNode.removeChild(anObj);
}

</script>

<table width="100%" border="2" cellspacing="0" cellpadding="0">
    <tr bgcolor="f0f3f9">
        <td width="100%">
            <div id="labels">
                <span class="formleft">LRN# <input type="text" name="lrnNo" size="20" value="<%= field1[i]%>" class="formstyle">  </span>
                <span class="formleft">Lab Test <input name="labTestDesc" type="text" class="formstyle" id="labtest" value="<%= field2[i]%>" size="20">  </span>
                <span class="formleft">Lab Result <input name="labResultDesc" type="text" class="formstyle" id="labResult" value="<%= field3[i]%>" size="20">  </span>
 <input name="Submit1" type="button" class="formbutton" value="Add " onclick="addLRN(this.parentNode);">
 <input name="Submit2" type="button" class="formbutton" value="Edit " onclick="editLRN(this.parentNode);">
 <input name="Submit3" type="button" class="formbutton" value="Remove" onclick="removeLRN(this.parentNode);">
            </div>
        </td>
    </tr>
    <tr bgcolor="f0f3f9">
        <td width="100%">
            <div id="labels">
                <span class="formleft">LRN# <input type="text" name="lrnNo" size="20" value="<%= field1[i]%>" class="formstyle">  </span>
                <span class="formleft">Lab Test <input name="labTestDesc" type="text" class="formstyle" id="labtest" value="<%= field2[i]%>" size="20">  </span>
                <span class="formleft">Lab Result <input name="labResultDesc" type="text" class="formstyle" id="labResult" value="<%= field3[i]%>" size="20">  </span>
 <input name="Submit1" type="button" class="formbutton" value="Add " onclick="addLRN(this.parentNode);">
 <input name="Submit2" type="button" class="formbutton" value="Edit " onclick="editLRN(this.parentNode);">
 <input name="Submit3" type="button" class="formbutton" value="Remove" onclick="removeLRN(this.parentNode);">
            </div>
        </td>
    </tr>
    <tr bgcolor="f0f3f9">
        <td width="100%">
            <div id="labels">
                <span class="formleft">LRN# <input type="text" name="lrnNo" size="20" value="<%= field1[i]%>" class="formstyle">  </span>
                <span class="formleft">Lab Test <input name="labTestDesc" type="text" class="formstyle" id="labtest" value="<%= field2[i]%>" size="20">  </span>
                <span class="formleft">Lab Result <input name="labResultDesc" type="text" class="formstyle" id="labResult" value="<%= field3[i]%>" size="20">  </span>
 <input name="Submit1" type="button" class="formbutton" value="Add " onclick="addLRN(this.parentNode);">
 <input name="Submit2" type="button" class="formbutton" value="Edit " onclick="editLRN(this.parentNode);">
 <input name="Submit3" type="button" class="formbutton" value="Remove" onclick="removeLRN(this.parentNode);">
            </div>
        </td>
    </tr>
</table>

0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
jaggernatAuthor Commented:
thanks for the code dude. it helped me a lot. Can you please help me out with other javascript questions i posted (html:radio validation ) and javascript calendar.


Regards
j
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.