Click here to Skip to main content
15,914,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the div id value.After getting the id i want append some text-fields to that div.Actually i am getting the div id value.But text-fields are not appending to div.It is erasing previous data and it is adding only one field.I want to add 3 text-fields.
Posted
Updated 28-Apr-12 1:04am
v2

How to get the div id value
If div has 'runat=server' then the ID can be accessed as:
JavaScript
// Access the div with it's ClientID
var divToAccess = document.getElementById("<%=whateverIsDivId.ClientID%>");


If div is a general HTML control without runat=server,
JavaScript
// Access the div with it's ID
var divToAccess = document.getElementById("whateverIsDivId");
 
Share this answer
 
Comments
VJ Reddy 28-Apr-12 11:02am    
Good answer. 5!
Sandeep Mewara 28-Apr-12 11:32am    
Thanks VJ.
I suggest JQuery
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Untitled Page</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
	 type="text/javascript"></script>
    <script type="text/javascript">
        function setFields() {
                $('#divResults').html($('#divResults').html() +
		"<input id='example1' type='text' />"+
		"<input id='example2' type='text' />"+
		"<input id='example3' type='text' />");
	}          
    </script>
</head>
<body>
    <div id="divResults" >
	test
    </div>
    <button  onclick="setFields()">set Fields</button>
</body>
</html>
 
Share this answer
 
v3
Comments
DeepthiTanguturi 28-Apr-12 8:00am    
It's not working
Nikfazan 28-Apr-12 9:41am    
It needed a little edit. The code was changed on upload. Check again. You must access to "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" too.
When you click on "set Fields" 3 input box will add to "test" string. Hope it help.
dipopeter2001 28-Apr-12 9:45am    
I guess you want to use javascript for that.
So, say the div is with the id divID
try this:

var myId = document.getElementById("divID");
//to append data use this
myId.innerHTML +="<br />my new text";

I believe that solves it. Let me know how else to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900