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
  • 2
  • 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ᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
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,779
  • 6
  • 38
  • 62
1

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

Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 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
  • 27,674
  • 12
  • 80
  • 107
0

you should be changing the innerHtml element instead

delDiv.innerHtml = 'your html';
CSharpened
  • 11,674
  • 14
  • 52
  • 86
0

Try setting the innerHTML property:

delDiv.innerHTML = '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>'
dash
  • 89,546
  • 4
  • 51
  • 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
  • 10,187
  • 1
  • 36
  • 43
-1

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

Jérémy Dutheil
  • 6,099
  • 7
  • 37
  • 52