By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,686 Members | 1,914 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,686 IT Pros & Developers. It's quick & easy.

small jquery problem

pradeepjain
100+
P: 563
i am building a select based on the values in a text box .
like

Expand|Select|Wrap|Line Numbers
  1. $("#pincode").change(function(){
  2. $.post("doctor_search.php",{ pincode:$("#pincode").val()} ,function(data){
  3. $("#suggestions").html(data);
  4. });
  5.     });
when ever a error occurs when the form is submitted the select does not work as ajax is a change function . how to say to jquery tht do it if the value in the text box is not null also i.e trigger a event ??
Nov 24 '09 #1
Share this Question
Share on Google+
11 Replies


acoder
Expert Mod 15k+
P: 16,027
Why not add a simple if condition which checks the value? If it's not empty. the request is made.
Nov 30 '09 #2

pradeepjain
100+
P: 563
hmm..yeah i thought of same logic..but i cld not write the if condition in jquery !! i am new to it !plzz can u show me the code !!only if condition?
Nov 30 '09 #3

acoder
Expert Mod 15k+
P: 16,027
Why not use regular JavaScript, except perhaps to reference an element? E.g.
Expand|Select|Wrap|Line Numbers
  1. if ($("#pincode").val() != "") {
Nov 30 '09 #4

pradeepjain
100+
P: 563
its something like this rite

Expand|Select|Wrap|Line Numbers
  1. if ($("#pincode").val() != "") {
  2. $("#pincode").change(function(){
  3. $.post("doctor_search.php",{ pincode:$("#pincode").val()} ,function(data){
  4. $("#suggestions").html(data);
  5. });
  6.     });
  7. }

I had written that code earlier only ! but did not work ! so i thought the code was wrong ! anyways will give it a try again and get back to you. thank you :)
Dec 1 '09 #5

acoder
Expert Mod 15k+
P: 16,027
No, that's not correct. Put the if statement inside the change function.
Dec 1 '09 #6

pradeepjain
100+
P: 563
but then error is other fields are discovered and errors are displayed again bcos of the
Expand|Select|Wrap|Line Numbers
  1. .change
i need to change the value in the pincode field for the jquery event to happen !!
Dec 1 '09 #7

acoder
Expert Mod 15k+
P: 16,027
So you want this to take place when the form is submitted even if there are errors?
Dec 1 '09 #8

pradeepjain
100+
P: 563
if the field has some value in it the event must be triggered !
Dec 1 '09 #9

acoder
Expert Mod 15k+
P: 16,027
Yes, but when? When should the check be made that there's some text in the field?
Dec 1 '09 #10

pradeepjain
100+
P: 563
when the user fills out the form 1st time its all okie .he fills the pincode thing so .change will work there . but say when the form has some errors and the same page is displayed with errors then the .change will not happen so i wanted to check if value is there in pincode then trigger the event !
Dec 1 '09 #11

acoder
Expert Mod 15k+
P: 16,027
When the same page is displayed with errors, is the page still the same (Ajax) or what it unloaded/reloaded?

I think it's best if you show the page where the problem occurs.
Dec 2 '09 #12

Post your reply

Sign in to post your reply or Sign up for a free account.