Hi,

I know for calling jquery function requires some event. But in my project I want to call function of jquery onchange event but that value changing through coding and whenever that value changed jquery function should be called.


That means upto particular condition value will be changed of textbox and uptill function of jquery should be called.

Thanks in advance.

Member Avatar for stbuchok

Can you give some code examples or sudo code?

<html><head><script>
		
		$(document).ready(function(){

			$("#callPegingId").ajaxError(function(e,xhr,opt){
				alert("Error requesting "+opt.url + ": "+xhr.status+" "+xhr.statusText+" :e = "+e+" "+xhr.responseText);
			})

			$("#callPegingId").change(function(){
					alert("testing hdButtonId.....");
				$.ajax({

					type: "POST",
					data: "sqlQry="+<%=qrySnd%>+"&recSearch="+$(this).val(),
					url: "birthSearchPegination.jsp",
					success: function(result){
						$("#hdButtonId").html(result);
					}
				})
			})
		})

	</script>
</head>
<form>
<input type="hidden" name="callPeging" id="callPegingId" value="check">
<%
// Here is if resultset contain some data then script will be executed

if(rs.next()){%>
											<script>
											    document.getElementById("callPegingId").value = 1;
										
											</script>
									   <%}%>
</form></html>

in the above application if textbox value change to 1 by satisfying if condition and then ajax code should be call.

Member Avatar for stbuchok

I think the change event will only fire when there is user interaction (user types into a textbox, selects something in a dropdown...). I think what you want is the following:

function callAjax(value){
	$.ajax({
		type: "POST",
		data: "sqlQry="+<%=qrySnd%>+"&recSearch="+value,
		url: "birthSearchPegination.jsp",
		success: function(result){
			$("#hdButtonId").html(result);
		}
	})
}

...

if(rs.next()){%>
											<script>
											    
callAjax(1);
 
											</script>
									   <%}%>

Thanx for reply,

if try to call callAjax method in jsp in if condition then it show error like -
The method callAjax(int) is undefined

please help me

Member Avatar for stbuchok

Show code please.

if I try ur above given solution then it shows me error is "object required" at where we have called callAjax(1) in if condition.

Member Avatar for stbuchok

I can't help you if you don't show the code you've changed. Please show all the code.

Perhaps what you need is this:

data: {sqlQry: '<%=qrySnd%>', recSearch: value}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.