0
<input type="checkbox" name="AvatarfileSelected" value="image" id="AvatarfileSelected" onclick="$('#extra').hide('slow')"/> <span style="color:#538f05;">Change Image</span> <div id="extra"> <input type="file" name="avatarfile" id="avatarfile"></input> </div> 

The above code doesn't work. Could someone show me the mistakes?

7
  • 1
    If that's the case you would see an error in the JavaScript console Commented Jul 3, 2012 at 21:19
  • 2
    @Blaine Nope; semi-colons in javascript are not required for the code to work. Commented Jul 3, 2012 at 21:25
  • input tags are self-closing in XHTML, btw (referring to #avatarfile) Commented Jul 3, 2012 at 21:28
  • @Blaine. Not required in js. Just teasing you... :) Commented Jul 3, 2012 at 21:28
  • @gdoron I'm genuinely confused now about the role of the semicolon in JavaScript in-line one-liners lol Commented Jul 3, 2012 at 21:31

2 Answers 2

3

You probably didn't include jQuery...

Use vanilla javascript:

onclick="document.getElementById('extra').style.display = 'none'"; 

Instead of:

onclick="$('#extra').hide('slow')" 

(Or include jQuery if you want to use it.)


BTW, <input> doesn't have a closing tag: </input>

Replace:

<input type="file" name="avatarfile" id="avatarfile"></input> 

With:

<input type="file" name="avatarfile" id="avatarfile" /> 
Sign up to request clarification or add additional context in comments.

Comments

0

Take out the onclick event from the HTML markup and do it in unobutrusive way. Make sure you bind your event functionalities in document ready event.

Use it like this

$(function(){ $("#AvatarfileSelected").click(function(){ $("#extra").hide(); }); });​ 

Jsfiddle sample : http://jsfiddle.net/p9tdf/1/

1 Comment

Though it's the right way to use jQuery, how does it answer the question...?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.