matt_739
matt_739

Reputation: 11

Change HTML Object using JavaScript

I am trying to develop a site that on entering a value into an input changes page content. I have gotten this to work with my photos. I am pulling text from a .txt file using HTML "Object".

I want to change the file path for the text file using the input as the parent folder. I tried using inner.html, and setting the id data = but neither worked.

I'm open to any suggestions.

function myFunction() {
  var x = document.getElementById("stud").value ;
  var a = x + "/img1.jpg" ;
  var b = x + "/img2.jpg" ;
  var text_hold = x + "/text/text.txt" ;
  img1.src= a ;
  img2.src= b ;
  document.getElementById("content").innerHTML = "data='jeff/stock/text/text.txt'" ;
}

Upvotes: 0

Views: 41

Answers (1)

Barmar
Barmar

Reputation: 780889

data is an attribute, it's not the HTML contents of the object. Use setAttribute to set it.

document.getElementById('content').setAttribute('data', 'jeff/stock/text/text.txt');

Upvotes: 1

Related Questions