SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Activate Button

  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Activate Button

    I have a jquery function that will upload an image to the server and then back to the html page. The image transfer works fine but I am trying to enable a button on transfer completion but I not meeting with success. I am sure I am missing something but do not see it. If anyone can offer a suggestion I would appreciate it. The function is

    Code javascript:
    $(document).ready(function()
    {
    	$('#image_upload_form').submit(function()
    	{
    		$('#product_type_image').attr('src', '../images/misc/loading.gif');
    	});
     
    	$('iframe[name=upload_to]').load(function()
    	{
    		var result = $(this).contents().text();
    		$('#button_three').attr('disabled', false); 
     
    		if (result != '')
    		{
    			if (result == 'Err:big')
    			{
    				$('#product_type_image').attr('src', '../images/misc/imagebig.png');
    				return;
    			}
     
    			if (result == 'Err:format')
    			{
    				$('#product_type_image').attr('src', '../images/misc/imageformat.png');
    				return;
    			}
     
    			$('#product_type_image').attr('src', $(this).contents().text());
     
                            $('#button_three').attr('disabled', false); <==== this is the code not working correctly, or at least as I think it should
    		}
    	});
    });

    Thanks
    Last edited by paul_wilkins; Apr 13, 2013 at 13:48. Reason: add code tags

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    The standard way to disable a button is with:

    Code javascript:
    $('#button_three').attr('disabled', 'disabled');

    which results in:

    HTML Code:
    <button id="button_three" disabled="disabled">...</button>
    To enable that button again, you remove the disabled attribute using the removeAttr method:

    Code javascript:
    $('#button_three').removeAttr('disabled');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the response and the lead.

    There must be something else going on because I tried this nine ways to Sunday and it does not work. I see no errors generated. I put a javascript alert tag immediately before the code in question and I do see a pop up notice and then a failure to execute.

    I am now working on the theory that the script does not see the button id for some reason. Problem is that the button is generated using the DOM createElement method so I am sort of working blind.

    Still learning. Thanks

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by enginemike View Post
    I am now working on the theory that the script does not see the button id for some reason. Problem is that the button is generated using the DOM createElement method so I am sort of working blind.
    It could be a matter of timing then. Can we see a test page that demonstrates the issue, from which we can investigate further?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Activate Button

    Hello. Hope I have this figured out.

    I placed all relevant files in the attached zip file. I believe the main thing is the menu.js file, specifically the function: addButton(name). That is where the issue is to be found. But better too much information rather than too little. The actual site is on my desk top server so I am afraid that you cannot access it.

    Basically this function opens an image upload window. The point is to send an image to the server and then display it on the html page. The button, button_three should become active when an image is loaded. Pressing the button will then place the image in the proper sever file. I have in mind to disable the button in the event of an error.

    Hope this makes sense.

    Thank you for taking a look. By the way, the next day or so I will be traveling so looking at the forum will be kind of hit or miss.
    Attached Files Attached Files


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
  •