SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit button not working

    When putting the following code into a page, none of the site's submit buttons work, except for the ones with class="submit". How can I fix that?
    Code JavaScript:
    $(function() {
    	$('.submit').click(function() {
    	var postID = $(this).attr('rel');
    	var comment = $('#com_comment'+postID).val();
    	var dataString = 'com_comment=' + comment + '&postID=' + postID;
     
    	if(comment=='') {
    		alert('Please enter a comment');
    	} else {
    		$('#flash'+postID).show();
    		$('#flash'+postID).fadeIn(400).html('<img src="/images/ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>');
    		$.ajax({
    			type: 'POST',
    			url: '/scripts/comments_ajax.php',
    			data: dataString,
    			cache: false,
    			success: function(html){
    				$('ol#update'+postID).append(html);
    				$('ol#update'+postID+'li:last').fadeIn('slow');
    				document.getElementById('com_comment'+postID).value='';
    				$('#flash'+postID).hide();
    			}
    		});
    	}
    	return false;
    	});
    });

  2. #2
    SitePoint Enthusiast TriLLi's Avatar
    Join Date
    Feb 2010
    Location
    BiH, Bugojno
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, Could you post HTML also.. it would be nice, and I see that you are using my example from previous post...
    http://www.wiseblog.info
    Programmers don't die, they just GO SUB without return.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Surely you can figure this one out...

    if you look at the second line, you see that the entirety of the code is applied to '.submit' - i.e. elements with the class "submit". If you want all input elements of type submit to have this applied to them, just replace the .submit with input[type=submit].

  4. #4
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    Surely you can figure this one out...

    if you look at the second line, you see that the entirety of the code is applied to '.submit' - i.e. elements with the class "submit". If you want all input elements of type submit to have this applied to them, just replace the .submit with input[type=submit].
    That was my first thought. However, all of the buttons on the site don't have the .submit class applied to them, they have a .button class. Yet, when this script is in a global .js file, none of the buttons on the site work.


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
  •