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
  • 15

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ᴏʀʏ
  • 97,417
  • 19
  • 158
  • 183
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,575
  • 5
  • 35
  • 61
1

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

Tom van der Woerdt
  • 28,143
  • 7
  • 67
  • 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
  • 25,567
  • 8
  • 75
  • 106
0

you should be changing the innerHtml element instead

delDiv.innerHtml = 'your html';
CSharpened
  • 9,906
  • 14
  • 47
  • 84
0

Try setting the innerHTML property:

delDiv.innerHTML = '<p>Upload Support Document</p><fieldset><input type="file" name="file" id="file" /></fieldset>'
dash
  • 84,786
  • 4
  • 48
  • 69
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,707
  • 1
  • 34
  • 41
-1

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

Jérémy Dutheil
  • 5,817
  • 6
  • 35
  • 51