Edit - Onclick Even To Happen Rather Than Wait For The Click
Apr 23, 2011
I have onclick code in a span tag that works fine. I want the onclick even to happen rather than wait for the click. How do I turn the onclick code into something that executes as the code is generated? I thought...
<span onclick"code xxx"><a>Link</a></span?
... could be changed to...
<script type="text/javascript">code xxx</script>
doesn't work...
I am using a custom dialog function which is called after an AJAX request to see if a file exists. This dialog shows a "Continue" or "Cancel" button and returns true or false depending on which button is clicked. It can also be switched between "alert" and "confirm" functions.
Here's the function: //Popup dialog function popup(message,mode) { // get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); // calculate the values for center alignment var dialogTop = (maskHeight/3) - ($('#dialog-box').height()); var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); // assign values to the overlay and dialog box ..... $('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show(); $('#dialog-box').css({top:dialogTop, left:dialogLeft}).show(); if(mode=="alert") { $('#continue, #cancel').hide(); $('#close').show(); $('#close').click(function() { $('#dialog-overlay, #dialog-box').hide(); return false; }); } else { $('#continue').click(function() { $('#dialog-overlay, #dialog-box').hide(); return true; }); $('#cancel').click(function() { $('#dialog-overlay, #dialog-box').hide(); return false; }); $('#continue, #cancel').show(); $('#close').hide();} // display the message $('#dialog-message').html(message); }
Here's how I call the function: success: function(result) { if(result==1) { if(!popup("<p>Plugin version exists. Overwrite?</p>","confirm")) { $('#file_upload').uploadifyCancel(); } else { $('#file_upload').uploadifyUpload(); }} else { alert("Doesn't Exist "); }
After a few tries I realised that the file was always being uploaded whether it existed or not. I then used the alert function to show me what is being returned from the popup() function and it was returning "undefined". Obviously the function isn't waiting for a response from the listeners. How can I change this so the function doesn't return until one of the buttons has been clicked?
I'm wondering how I can have the same function thats used on this site, has any one here every noticed that if you view the topic list on this site, and double click on a topic that you made, it brings up an edit option for the subject? just wondering how this is done? Code:
I am clicking on an anchor tag which calls some JQuery code, which posts to an Action method that loads a different page. When I remove the JQuery and just call the Action method, the redirect works fine. But when I add the JQuery (I need this in order to pass some parameters on the anchor onclick event), although the action method gets called, the redirect does not happen.what is wrong with my code that could be causing this?
$( ".screenshot-link").click(function () { var site = $(this).attr("site");
I have a calendar view made up of div tags for each day. I can highlight a number of days in a column by clicking on one and holding down shift and clicking on another one. each div tag is called "boxX_Y" where Y is the column and X is the row. The javascript knows the first clicked box, and the second and changes the style.className for the boxes in between based on the Y value.
Trouble is, when selecting about 30 boxes it takes a while to change the style.className, so I would like to display a message to say "Please wait". I've done this by creating another div tag called wait_message, and set the visibility to "visible" when the function to highlight the boxes is called. However, the wait message box isn't displayed until the loop for changing the classNames has finished, even though the wait_message visibility code is above the loop.
Is there any way to make the code take effect straight away rather than waiting for the whole function to be computed?
how can i make the actions happen all together at the same time, not in a series for instance this code will show the balloon first which takes 100th of a second then go to the next list i want this list to happen at once
The jQuery breaks in IE8. If you click the first image on this page, either one of two things will happen the PNG file will load or nothing will happen. To understand compare in FireFox/Chrome.
I'm using the following piece of code to create a link that, when clicked, uses jquery animation to slowly display a paragraph of text. The trouble is that the animation goes both vertically and horizontally, making it look a little too busy/cluttery. How can I tweak my code to make it only animate vertically?
I am writing a chrome extension.In this extension i append a img tag to the dom. Then i read the width and the height of the picture to adjust it to the viewport size. The problem is that when i read the dimensions right after adding the img tag i get zero with and height. I could fix that if i make a setTimeout between adding img and read size.
Could anyone please tell me if there is any way i can have the text "Menu Loading Please Wait..." appear while the js menu loads and then disappear after it loads?
Now what i want to do is: i have a callajax() function. with in this function i will call do_login() function. this do_login() handles an ajaxrequest and returns the responsetext.
Now i want to do some validation on this responsetext(in case of onsuccess). so i am trying to return value to callajax() function for onSuccess case in ajaxrequest.submit();
That is(onsuccess response) supposed to be some string( but not true or false). but i am always getting false in ajaxcall() function. i know the do_login() function is returning false before ajaxrequest completes
So i want to stop this and make do_login wait until ajaxrequest completes and then i want to return it's response to callajax() function.
I'm trying to use Google's Translate API. I copied (and adapted) the example below from here. I would like to input the text to translate, instead of having value="I cannot input my text", but I do not know how to make the script wait for input.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>
[code]....
I know this should be very simple but I'm new to all this, so if anybody could indicate what changes I need to make to the html and/or script to translate the text I input.
I have a calculation system that uses ajax with php and xml and executes with onkeyup. The only problem with this is the result can be returned before the user finishes entering the entire number. My question is how can I give a delay prior to running the rest of the js.I know how to use setTimeout() but will it get reset out every time the function is called or for example if they enter 5 characters in the form, will the script be called 5 times with a second delay from each or will it only be called once? Is there a performance degradation involved?
I'm calling a recursive function, and I want to display an alert after its done running, the thing the function is "done" after goes through it once.Here's the coles notes version....
Code:
function yay(n){ n = n-1; if(n=0){
[code]....
I don't want it to show the alert until its done all of it's recursive splendor.
When you login to Paypal, it displays a progress bar type gif and then the page loads when the authentication is complete. How to implement this with js? How does js script know that it is time to proceed to the next page?
I have report that takes about 5-10 seconds to generate depending on the load. I want to show the user a progress bar while it is being generated and when it's done, forward the browser to the report.
I have tried to write a wait function but it seems like it will not brake the while loop. I tried two different solutions. Can anyone tell me what I am doing wrong, and come with another suggestion? If I call the function like this: wait(500); it should wait 500ms right?
function wait(time) { while(1){ setTimeout("break;",time); } }
function wait(time) { var flag=0; while(flag=0){ setTimeout("flag=1;",time); } }