www.webdeveloper.com
Results 1 to 5 of 5

Thread: Call jQuery function from Javascript

  1. #1
    Join Date
    Sep 2009
    Posts
    172

    Call jQuery function from Javascript

    All,
    I have the following JS function:
    Code:
    <script language="javascript">
    function uploaderStatusChanged( uploader ) {
    	upload_status = uploader.getStatus()
    	if(upload_status==1){
    	traceEvent( "The files are being uploaded!" );
    	testFinish();
    	}else{
    	traceEvent( "The files have successfully uploaded!" );
    	}
    }
    </script>
    I'd like to call the testFinish() function in here but I have this in a jQuery code:
    Code:
    <script>
    $(function() {
    	function testFinish(){
    	alert("its finished");
    	}
    });
    </script>
    How can I call the functions within jQuery from my original Javascript function? Thanks in advance.

  2. #2
    Join Date
    Feb 2011
    Location
    israel
    Posts
    157
    why did you put it in a jQuery? it wouldve worked the same if you dropped the $(), and wrote it as a simple javascript function. and this way you couldve called it easily as well.
    anyways, i think you could call it from your javascript if you just put the call in the $() as well:
    Code:
    $(function() {
    	function testFinish(){
    	alert("its finished");
    	}
    });
    $(function () {
    testFinish();
    });

  3. #3
    Join Date
    Sep 2009
    Posts
    172
    Here is the code the complete code that I'm trying to use. The uploaderStatusChanged() is called from the uploader (I'm using Jumploader). I tried to put this in the jQuery but it wouldn't work if I took it out of the regular javascript tags. I'd like it to call the jQuery function testFinish() after the images are done being uploaded. Not sure how to updated this code to make that happen. Any ideas would be greatly appreciated. Here is the complete code:

    Code:
    <?php
    session_start();
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title></title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/reset.css" type="text/css" media="screen">
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
    <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen">
    <script type="text/javascript" src="js/jquery-1.4.2.min.js" ></script>
    <script src="js/cufon-yui.js" type="text/javascript"></script>
    <script src="js/cufon-replace.js" type="text/javascript"></script>
    <script src="js/Journal_400.font.js" type="text/javascript"></script>
    <script>
    $(function() {
    	function testFinish(){
    	alert("its finished");
    	}
    });
    </script>
      <![if lt IE 7]>
       		<script type="text/javascript" src="ie6_script_other.js"></script>
    	<![endif]
        <![if lt IE 9]>
       		<script type="text/javascript" src="js/html5.js"></script>
    	<![endif]
    </head>
    
    <body id="page2">
    	<div class="main">
    		<!-- header -->
    		<?php include "header.php"; ?>
    	</div>
    		<!-- content -->
    		<section id="content">
    			<?php include "navigation.php"; ?>
    				<div class="inner">
    					<div class="main">
    						<div class="indent1">
    							<div class="main">
    								<a class="item1 current" href="upload_pictures.php">Upload Photos From Your Computer</a>
    							</div>
    <br><br><br>				
    Please upload your photos to our site below:<br><br><strong>Allowable file extensions: .jpg, .gif, .png</strong><br><br>
    <div id="upload_done"></div>
    <applet id="jumpLoaderApplet" name="jumpLoaderApplet"
    	code="jmaster.jumploader.app.JumpLoaderApplet.class"
    	archive="jumploader_z.jar"
    	width="870"
    	height="600"
    	mayscript>
    <param name="uc_imageEditorEnabled" value="true"/>
    <param name="uc_uploadUrl" value="partitionedUploadHandler.php"/>
    <param name="vc_uploadViewStartUploadButtonText" value="Start upload"/>
    <param name="vc_uploadViewStartUploadButtonImageUrl" value="/img/media_play_green.png"/>
    <param name="vc_uploadViewStopUploadButtonText" value="Stop upload"/>
    <param name="vc_uploadViewStopUploadButtonImageUrl" value="/img/media_stop_red.png"/>
    <param name="uc_fileNamePattern" 
    value="^.+\.((jpg)|(jpe)|(jpeg)|(JPG)|(JPE)|(JPEG)|(gif)|(GIF)|(png)|(PNG))$"/>
    <param name="vc_disableLocalFileSystem" value="false"/>
    <param name="vc_mainViewFileTreeViewVisible" value="true"/>
    <param name="vc_mainViewFileTreeViewVisible" value="true"/>
    <param name="uc_imageRotateEnabled" value="true"/>
    <param name="uc_directoriesEnabled" value="true"/>
    <param name="uc_addImagesOnly" value="true"/>
    <param name="uc_partitionLength" value="100000"/>
    <param name="ac_fireUploaderStatusChanged" value="true"/>
    </applet>
    
    <script language="javascript">
    function uploaderStatusChanged( uploader ) {
    	upload_status = uploader.getStatus()
    	if(upload_status==1){
    	traceEvent( "The files are being uploaded!" );
    	testFinish();
    	}else{
    	traceEvent( "The files have successfully uploaded!" );
    	}
    }
    </script>
    <script language="javascript">
    function traceEvent( message ) {
    	document.getElementById("upload_done").innerHTML = '<font color="red">'+message+'</font><br /><br />';
    }
    </script>
    <br><br>					
    						</div>
    					</div>
    				</div>
    		</section>
    	
    	<!-- footer -->
    	<?php include "footer.php"; ?>
       <script type="text/javascript"> Cufon.now();</script>
       </script>
    </body>
    </html>

  4. #4
    Join Date
    Feb 2011
    Location
    israel
    Posts
    157
    well, of course it would'nt work, you call a function by its wrong name!
    right now, your testFinish() is stuck in a jquery function... so my first advice is.. let it out of there. there is nothing jquery in a simple alert. just delete the orange part from
    Code:
    $(function() {
    	function testFinish(){
    	alert("its finished");
    	}
    });
    if, for some unreasonable unlogical reason that does not work, youll just have to turn every call for this function jquery, like this:
    Code:
    $(function () {
    testFinish();
    });
    good luck, let me know how this worked out... ^_^

  5. #5
    Join Date
    Sep 2009
    Posts
    172
    This worked, I'm not sure why but I thought you could only use jQuery if it is was in the

    Code:
    $(function() { }
    My new testFinish() looks like this:
    Code:
    function testFinish(){
    	alert("its finished");
    	$("#upload_text").html("This works");
    }
    It works fine. Thanks for the help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles