0

I want to show an error alert box inside the if block in jquery but error is coming. Can anybody help me here. I have found alert box from this website but in that case i have to click on Error Message Popup Alert to see the alert, but how can i add that Error Message Popup Alert alert inside my jquery if part so that without click that alert box will apear?

 $("#textbox").keyup(function () {
    $.getJSON('check.jsp', {
        textboxname: this.value
    },function(data){
      if(data.isTrue){
          $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert
      }
      else{
       //do something 
      }             
     });
});
5
  • you can do it inside the if block what is the error you are getting Commented Feb 18, 2012 at 10:18
  • actually no alert box is appearing have you seen that website i have to click on Error Message Popup Alert alert to appear the alert but without any click it is not appearing Commented Feb 18, 2012 at 10:21
  • @3nigma any suggestion please Commented Feb 18, 2012 at 10:30
  • the answer by @Chamika Sandamal should solve your problem Commented Feb 18, 2012 at 10:33
  • i have posted an answer with the demo add the js files inside the head section Commented Feb 18, 2012 at 10:41

3 Answers 3

1

call it like following code,

$("#textbox").keyup(function () {
    $.getJSON('check.jsp', {
        textboxname: this.value
    },function(data){
      if(data.isTrue){
          $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert
          csscody.alert(data);
      }
      else{
       //do something 
      }             
     });
});
Sign up to request clarification or add additional context in comments.

8 Comments

thanks for your answer but can you please add that Error Message Popup Alert(at 2nd position) from this website?
ok but what is this csscody? i have to write css coding in that function?
csscody is a JavaScript library. you don't need to do anything inside it. just add reference and call it. and if this solved your problem mark as answer.
you have to pass the data to the message. data.someProperty
ya it worked but after alert why some of other textboxes are being vanished? when i am refrshing that page then only these vanished textboxes are appearing. Any help please
|
1
if(data.isTrue){
    $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert
    csscody.alert('<h1>Hello World</h1>');
    return false;

}

Comments

0

include the following js files in your HEAD section

http://csscody.com/demo/wp-content/demo/popup/js/jquery.easing.1.3.js

http://csscody.com/demo/wp-content/demo/popup/js/alertbox.js

http://csscody.com/demo/wp-content/demo/popup/js/style.css

then in the success handler inside the if block alert the message like

$("#textbox").keyup(function () {
    $.getJSON('check.jsp', {
        textboxname: this.value
    },function(data){
      if(data.isTrue){
           csscody.alert("user name already exists");
          $("#textbox").val(''); //clear the text box and show that Error Message Popup Alert

      }
      else{
       //do something 
      }             
     });
});

DEMO

8 Comments

ya i included all files in head section but still it is not working like that alert.
in your demo it working fine but in your above code i cannot find any success handler
AH! the function which you pass as the second argument of the getJSON function is called success handler
ya it worked but after alert why some of other textboxes are being vanished? Any help please
did you selected the text box by id ? then it means you are using idetical ids on the page which is a bad practice, ids have to be unique
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.