0

Here's my button:

<p>File Uploaded:</p><fieldset><div id='fileloc'>"PROGRAMMATICALLY INSERTED LINK TO FILE" <button type='button' onclick='fileDelete()'>Delete</button></div></fieldset>

And here's my script to try to replace the values in the div with an upload button.

    <script type="text/javascript">
        var fileDelete = function() {
            var delDiv = document.getElementById("fileloc")
            delDiv.value('<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>');
        }
    </script>

However I get the error:

delDiv.value is not a function.

Would I run document.delDiv? How would I go about doing this correctly?

Ryan Schafer
  • 245
  • 1
  • 9
  • 16

8 Answers8

2

You should use delDiv.innerHTML = '<p>...'; instead. The value attribute exists typically for <input> elements, not <div>s.

Also, any reason you're doing var fileDelete = function() {} vs. function fileDelete() {}? See var functionName = function() {} vs function functionName() {} for the difference and whether one way applies to your problem over the other.

Community
  • 1
  • 1
Cᴏʀʏ
  • 101,556
  • 20
  • 162
  • 188
1

I do not think it's value that you want, but innerHTML

document.getElementById("fileloc").innerHTML = '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>';

djdy
  • 6,733
  • 5
  • 36
  • 62
1

Use delDiv.innerHTML = '<p>...</p>';

Tom van der Woerdt
  • 28,913
  • 7
  • 68
  • 105
1

It's not a value, it's inner markup. Try this:

delDiv.innerHTML = '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>';
Polynomial
  • 26,720
  • 10
  • 77
  • 106
0

you should be changing the innerHtml element instead

delDiv.innerHtml = 'your html';
CSharpened
  • 10,654
  • 14
  • 49
  • 85
0

Try setting the innerHTML property:

delDiv.innerHTML = '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>'
dash
  • 87,236
  • 4
  • 50
  • 71
0

value is a property of the element, so it is set through the assignment operator:

delDiv.value =
    '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>';

However, I think your intent here is to set the HTML inside:

delDiv.innerHTML = 
    '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>';

...oh, and you forgot a semicolon on the previous line ;)

Thomas Kelley
  • 9,969
  • 1
  • 35
  • 41
-1

You should use innerHTML : delDiv.innerHTML = "..."

Jérémy Dutheil
  • 5,937
  • 6
  • 36
  • 52