thiago
thiago

Reputation: 101

Get id value using <input> with javascript and php

First example:

var dbSelected = "File selected: ";
var filenamePanel = document.getElementById('filenamePanel');
filenamePanel.textContent = dbSelected + files[0].name;

var postLink = files[0].link;
document.getElementById('postLink').value = postLink;

var postName = files[0].name;
document.getElementById('postName').value = postName; 

If I use <input type="hidden" name="postName" id="postName"> to send the value to another page via POST with PHP, it works.

Second example:

function onSuccessCallback(Blob){
    document.getElementById('postName').textContent = Blob.filename;
    document.getElementById('postLink').textContent = Blob.url;
    document.getElementById('results').textContent = JSON.stringify(Blob);            
};

Now, If I use <input type="hidden" name="postName" id="postName"> on the second example to send the 'postName' id value to another page, the value is empty.

What changes are necessary, on the second example, so that I can send the 'postName' id value to another page using a hidden <input> field?

Upvotes: 0

Views: 1120

Answers (1)

Mario A
Mario A

Reputation: 3363

Use .value instead of .textContent to store the data in the hidden input field:

document.getElementById('postName').value= Blob.filename;

Upvotes: 1

Related Questions