Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Add data Dynamically in JSP

Status
Not open for further replies.

ash298

Programmer
May 16, 2007
1
US
Hi,
I am new with JSP. In my program, I have JSP interface,where user should be able to add,delete and edit customer names.
I have a ADD button,and I am calling addition() funcation on clickevent of ADD button, so I have to write code in my Addition() function (which is in Javascript)
Can you tell me how can I add data dynamically?
If you can explain with sample code, i will really appreciate it.

Many thanks in advance
-Ash
 
Ash,

I am also fairly new, but as no-one else has replied I'll have a go...
Note i'm a c++ programmer at heart, so my code isn't exact (especially capitalisation etc) but hopefully it gives a starting point

It of course depends on how you are storing the data
Assuming your using some sort of XML data structure,
eg.

<customer data>
<customer id="00001">
<cname name="Big Fat Customer"/>
</customer id>
</customer data>

then you should read up on how to use
selectnodebyid
selectnodesbytag
xpath expressions
insertafter
insertbefore
appendchild
etc

for example
var x = document.selectnodebyid("00001"); // returns an Xml node for this id
x.insertAfter(newnode,x);
// add a new sibling customer id node
// -- will insert your new node after the id 00001

or
var x = document.selectnodesbytag("customer data"); // returns an xml node list for these tags
x.appendChild(newnode); // might need to be x[0].appendchild(newnode);

does the same thing

in both cases, you can create your new node like this:

var newnode = document.createElement("customer"); // create a node with tag 'customer'
var attrib = newnode.createAttribute("id"); // create an attrib for the customer node
attrib.value = "00002"; // set the id
newnode.attributes.append(attrib); // add the attributes to the new node
// now do the same for the customer name node
var customernamenode = newnode.createElement("cname");
var attrib2 = customernamenode.createAttribute("name");
attrib2.value="Even Fatter Customer";

customernamenode.attributes.append(attrib2);
// and append the name node to the new id node
newnode->appendChild(customernamenode);

// finally as above append to customer data

x.appendChild(newnode);

Hope it helps a bit
Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top