SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    934
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Combining javascript with jQuery, is this okay?

    Hi guys,

    I want to validate a form with JavaScript first and then call jQuery codes afterwards.
    Is this fine?
    or Should I use 100% jQuery?

    Below is the codes that I'm trying to test, I'm not sure if this okay.
    Code:
    	<script>
    		function IsEmpty(){
    		  if(document.forms['frm'].question.value == "")
    		  {
    			alert("Question must no empty!");
    			return false;
    		  }
    		  else {
    			$(document).ready(function() { 
    				//elements
    				var progressbox 	= $('#progressbox');
    				var progressbar 	= $('#progressbar');
    				var statustxt 		= $('#statustxt');
    				var submitbutton 	= $("#SubmitButton");
    				var myform 			= $("#frm");
    				var output 			= $("#output");
    				var completed 		= '0%';
    
    
    				$(myform).ajaxForm({
    					beforeSend: function() { //brfore sending form
    						submitbutton.attr('disabled', ''); // disable upload button
    						statustxt.empty();
    						progressbox.show(); //show progressbar
    						progressbar.width(completed); //initial value 0% of progressbar
    						statustxt.html(completed); //set status text
    						statustxt.css('color','#000'); //initial color of status text
    					},
    					uploadProgress: function(event, position, total, percentComplete) { //on progress
    						progressbar.width(percentComplete + '%') //update progressbar percent complete
    						statustxt.html(percentComplete + '%'); //update status text
    						if(percentComplete>50)
    							{
    								statustxt.css('color','#fff'); //change status text to white after 50%
    							}
    						},
    					complete: function(response) { // on complete
    						//output.html(response.responseText); //update element with received data
    						//myform.resetForm();  // reset form
    						submitbutton.removeAttr('disabled'); //enable submit button
    						progressbox.hide(); // hide progressbar
    						alert("Data successfully saved!");
    					}
    				});
    			}); 		  
    		  }
    		}
    	</script>
    As you can see I have inserted the jQuery codes inside the if else block of javascript codes.
    Is this fine?

    Any advice please.
    Thanks in advanced.
    Quality codes are optimized and tested...
    Click here for inspiration..

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by solidcodes View Post
    Hi guys,

    I want to validate a form with JavaScript first and then call jQuery codes afterwards.
    Is this fine?
    or Should I use 100% jQuery?
    In your opinion, can you do this in js:

    Code:
    function myfunc()
    {
    
         console.log('hello world');
    }
    
    myfunc();

  3. #3
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,108
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    or Should I use 100% jQuery?
    No, you should learn JavaScript and use the native functions whenever appropriate.
    jQuery just makes certain parts of JavaScript a lot easier and cross-browser compatible(like DOM, Events and Ajax), the aim should never be to write jQuery all the time.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And according to a recent sitepoint article, the aim may be to not write jQuery any time.

  5. #5
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    934
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @7stud

    Can you post the URL of the article here.
    Thanks in advanced.
    Quality codes are optimized and tested...
    Click here for inspiration..

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.sitepoint.com/do-you-really-need-jquery/

    Be sure to read the comments as well.


Bookmarks

Posting Permissions

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