Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Check checkbox if file upload has been selected - not working

    Hi, I got this script. I need to enable the checkbox if a file has been selected. I just cant seem to get it to work.

    Here is my page:

    Code:
    <!doctype html>
    <html lang="en">
    <head>
    	<meta charset="utf-8">
    	<title>jQuery Tutorial</title>
    	<link rel="stylesheet" type="text/css" href="">
    	</head>
    	<body>
    	<form action="#" method="post" enctype="multipart/form-data">
    		<input id="file" type="file">
    		<input id="imageChecked" type="checkbox" value="imageChecked" unchecked>
    	</form>
    		<script type="text/javascript" src="jquery.js"></script>
    		<script type="text/javascript" src="ext.js"></script>
    	</body>
    	</html>
    and here is my jquery code

    PHP Code:
    $(document).ready(function() {
        $(
    '#file').change(function() {
        $(
    '#imageChecked')this.removeAttr('unchecked');
        });
    }); 
    Any help is much appreciated

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    There is no such attribute as unchecked in HTML. And, in any case, you don't want to remove or add the attribute: checked is a *property* of a checkbox, not an attribute, per se. jQuery uses prop( ) for changing properties.

    Your placement of this in there is utterly wrong.

    You just want to check the box:
    Code:
        $('#imageChecked').prop('checked', true);
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Oh, and that means your HTML is bogus, too. Remove the unchecked from your <input> tag.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    And. by the by, your <form> there is useless.

    When it is submitted, *NO INFORMATION AT ALL* will be sent to the receiving page.

    That's because *ONLY* <form> fields with name= are sent by HTML to the receiving page. A field can have an id, true, but that id will *NOT* impact whether or not the field's value is sent to the receiving page. Only the name will do that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thank you yet again Old Pedant Its all working now thank you. The form I posted was just a example, the form i am using it is way to big to post lol.

    Many Thanks


  •  

    Posting Permissions

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