Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 75825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:34:37+00:00 2026-05-10T20:34:37+00:00

I have this piece of Javascript and it just won’t work. I allready checked

  • 0

I have this piece of Javascript and it just won’t work. I allready checked JSlint but that said everything works. Still doesn’t work. The javascript is located not in the HTML but is linked in the <head>

note: I am working with a local server, so pageload in instant.

function changeVisibility() {     var a = document.getElementById('invisible');     a.style.display = 'block'; }  var changed = document.getElementById('click1'); changed.onchange = changeVisibility; 

This here is the corresponding HTML

<input type='file' name='click[]' size='35' id='click1' /> <div id='invisible' style='display: none;'>   <a href='javascript:addFileInput();'>Attach another File</a> </div> 

So what happens is I click on the input, select a file and approve. Then then onchange event triggers and the style of my invisible div is set to block.

Problem is, I keep getting this error:

‘changed is null: changed.onchange = changeVisibility;’

i don’t get it, I seriously don’t get what I’m overlooking here.


EDIT: question answered, thank you Mercutio for your help and everyone else too of course. Final code:

function loadEvents() {     var changed = document.getElementById('click1');     var a = document.getElementById('invisible');     document.getElementById('addField').onclick = addFileInput;      changed.onchange = function() {         a.style.display = 'block';     } } if (document.getElementById) window.onload = loadEvents; 

This here is the corresponding HTML:

<input type='file' name='click[]' size='35' id='click1' /> <div id='invisible' style='display: none;'>   <a href='#'>Attach another File</a> </div> 

Also, thanks for the link to JSbin, didn’t know about that, looks nifty.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:34:37+00:00Added an answer on May 10, 2026 at 8:34 pm

    This sounds like the DOM object doesn’t exist at the time of referencing it. Perhaps change your code to execute once the document has fully loaded (or place the javascript at the bottom of your page)

    note: I am working with a local server, so pageload in instant.

    that’s not the issue – the constituent parts of a document are loaded in order. It doesn’t matter how fast they are loaded, some things happen before others 😀

    The onlything I’d like to do now is remove the Javascript link from the …

    Place an id on there, and inside your function do this:

    document.getElementById('addField').onclick = addFileInput; 

    Or, as you already have the div as the variable ‘a’:

    a.firstChild.onclick = addFileInput; 

    But this obviously leaves you with an invalid anchor tag. Best practice suggests that you should provide a way to do it without javascript, and override that functionality with your javascript-method if available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code I'm trying to get to display but no
I have a piece of XML that is structured similar to this: <root> <score
I have this piece of javascript which is supposed to validate on the clientside.
I have this piece of code (summarized)... AnsiString working(AnsiString format,...) { va_list argptr; AnsiString
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this piece of code: var myObj = function () { this.complex =
I have a piece of code looking like this : TAxis *axis = 0;
I have this code in jQuery, that I want to reimplement with the prototype
I've recently come across this piece of JavaScript code: if (,>=,<=,<>,.indexOf(, + sCompOp +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.