?
Solved

javascript add,edit remove in jsp page

Posted on 2006-03-28
3
Medium Priority
?
170 Views
Last Modified: 2008-03-17
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

0
Comment
Question by:jaggernat
  • 2
3 Comments
 
LVL 11

Expert Comment

by:mvan01
ID: 16315112
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
 
LVL 11

Accepted Solution

by:
mvan01 earned 2000 total points
ID: 16317382
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
 
LVL 10

Author Comment

by:jaggernat
ID: 16348011
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question