it_is_a_literature it_is_a_literature - 1 month ago 5
Javascript Question

How to combine the two input elements into one input element to do the same task?

<input type="file" id="file" /><input type="button" value="display text" onclick="readAsText();"/>


There are two inputs ,the first to select file to be uploaded,the second one to read it as text (omitted the readAsText() function).

How to combine the two input elements into one input element to do the same task?

What i want is just to click one button ,the file can be selected and readAsText function can be executed,not to put them all in one div.

It is so simple to put them into one div element.

<div><input type="file" id="file" /><input type="button" value="display text" onclick="readAsText();"/></div>

O_Z O_Z
Answer

Hope I understood the question.

I would use onchange because when you click the value is not yet updated. This should work

<input type="file" id="file" onchange="readAsText(this.value);" />