Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

javascript or jquery

Hi, I have the following code a mixture of jquery and javascript and i want that when i click my button, it calls the function onClick event and i want the error message to appear for 2 seconds and should hide, but currently they are not doingas such

function mydata(frmname)
{
	  var r = $("select#reasonName").val();
	  if($('#pList').is(':empty')) {
		  $("span#error").show().delay(2000).queue(function(n) {
	    	  $(this).hide(); n();
	      });
	  }
	  else if (r == 0) {
		   $("label#mylabel_error").show().delay(2000).queue(function(n) {
			   $(this).hide(); n();
		   });
	      $("select#reasonName").focus();
	      	return false;
	  }
	var lstProjects = document.getElementById("mylist").value;
	var reasons = document.getElementById("reasonName").value;
	ColdFusion.navigate('abc.cfm?ID='+mylist+'&rs='+reasonName,'div','','');
} 

Open in new window


In front end i am showing the error in the Span and the Label tags whose display:none; has been set initially

So pleae guide what is wrong in this
Avatar of jmnf
jmnf
Flag of Mexico image

I believe this is what you're looking for...

// Show dialog on some event
showDialog();

// Close dialog on same event right after opening using setTimeout
setTimeout(hideDialog(), 2000);

// this goes in your javascript block
function showDialog(){
    $( "#dialog" ).dialog();
}

function hideDialog() {
    $("#dialog").dialog({
        hide: "fadeOut"
    });
}

Open in new window


Hope it helps
Avatar of Coast Line

ASKER

well do not where do i place my other calls
Try this, backup current "function mydata(frmname)" and replace the "if" statement inside it with this one:

if($('#pList').is(':empty')) {
    setTimeout(function() {
        $("span#error").dialog();
    },2000);
}
else if (r == 0) {
    setTimeout(function() {
        $("label#mylabel_error").dialog();
    },2000);
    $("select#reasonName").focus();
    return false;
}

Open in new window

but i need that mydata code also, i know this will work, i need implementation with that that

Regards
function mydata(frmname)
{
    var r = $("select#reasonName").val();

    if($('#pList').is(':empty')) {
        setTimeout(function() {
             $("span#error").dialog();
        },2000);
    }
    else if (r == 0) {
        setTimeout(function() {
            $("label#mylabel_error").dialog();
        },2000);
        $("select#reasonName").focus();
        return false;
    }

    var lstProjects = document.getElementById("mylist").value;
    var reasons = document.getElementById("reasonName").value;
    ColdFusion.navigate('abc.cfm?ID='+mylist+'&rs='+reasonName,'div','','');
}
Forgot to enclose it on code, BTW you probably need to use "lstProjects" instead of "mylist" and "reasons" instead of "reasonName" inside of your Colfusion.navigate function
i get this issue

$("span#error").dialog is not a function
My bad...

dialog() is a function in jQuery UI, not only is jQuery needed, bu also jQuery UI... you can download it from the site:

http://jqueryui.com/download

or load it from google CDN:

http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js

and here's the dialog() documentation page:

http://jqueryui.com/demos/dialog/

i do not want the dialog UI
SOLUTION
Avatar of jmnf
jmnf
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial