javascript - Using document.getElementById() in IE 9 and previous versions -


this question has answer here:

i have web page used upload file. there 2 input fields on form. 1 of type text used give file name in our database. other of type file select file upload.

<input type="text" name="docname" id="docname" size="35" value="" /> <input type="file" name="importfile" id="importfile" size="35" onchange="refreshfilename();"/> 

i want use javascript extract actual file name (minus file path) "importfile" field once it's selected , auto-populate field "docname" value. javascript looks this:

function refreshfilename(){ var filename = document.getelementbyid('importfile').value;   var str = filename.split("\\"); var length = str.length;  document.getelementbyid('docname').value = str[length-1];  } 

this seems work file in chrome, firefox , ie 10 or 11. doesn't seem work in ie 9 or earlier versions. nothing have tried seems solve problems. suggestions on how can work earlier version of ie (i've thought of idea "just tell users not use ie").

if problem you're getting full path in ie, try this:

var filename = document.getelementbyid("importfile").value; document.getelementbyid('docname').value = filename.match(/[^\/\\]+$/); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -