i want to refresh a div on the basis of input ...here is a sample code:
<%@ page language="java" contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
</head>
<body>
<input type="button" id="1" value="1" onClick="javaScript:update('1');"/>
<input type="button" id="2" value="2" onClick="javaScript:update('2');"/>
<%
int value=1;
%>
<div id="refresh">
<%=value %>
</div>
<script type="text/javascript">
function update(input)
{
value=input;
alert(value);
}
</script>
</body>
</html>
so here is what i want when page loads it will print 1 as value is initialized with 1 but if i click 2 i want that div to print 2 whose value gets updated in update function of java script ...i don't want to refresh whole page just want to refresh that div ...i don't want to use JQUERY.load as it loads the whole page in div i just want to refresh that div
i want to refresh a div on the basis of input ...here is a sample code:
<%@ page language="java" contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
</head>
<body>
<input type="button" id="1" value="1" onClick="javaScript:update('1');"/>
<input type="button" id="2" value="2" onClick="javaScript:update('2');"/>
<%
int value=1;
%>
<div id="refresh">
<%=value %>
</div>
<script type="text/javascript">
function update(input)
{
value=input;
alert(value);
}
</script>
</body>
</html>
so here is what i want when page loads it will print 1 as value is initialized with 1 but if i click 2 i want that div to print 2 whose value gets updated in update function of java script ...i don't want to refresh whole page just want to refresh that div ...i don't want to use JQUERY.load as it loads the whole page in div i just want to refresh that div
Share Improve this question asked Apr 10, 2013 at 2:19 user2137186user2137186 8376 gold badges23 silver badges39 bronze badges 1- 1 (OT) why not encode in UTF8 ? – Roko C. Buljan Commented Apr 10, 2013 at 2:21
1 Answer
Reset to default 2function update(input)
{
$("#refresh").html(input)
}
That should be all you need
.html()
is the jQuery function that changes the innerHTML of an element.
For ajax you can look at the jquery docs here and this is a nice looking example for jQUery + php