When I add the Replace does not display?

the <script>
 function myFunction() {
 var x = document.getElementById("mySelect").value;
 var y = x.replace( /.*//, "" );
 document.getElementById("demo").innerHTML =y;

}

 </script>
June 14th 19 at 20:34
3 answers
June 14th 19 at 20:36
Solution
<form action method="post" enctype="multipart/form-data">
 <label for="answer">Պատասխան</label>
 <div class="form-group">
 <textarea id="DescriptionNew" onkeypress="return _checkLength(this,255,event)" onchange="return _checkLength(this,255,event)" name="answer" style="width: 100%;height: 200px;"></textarea>
 <label for="fileUpload_oafileUpload" class="custom-file-upload">
 <i class="fa fa-file-photo-o" style="font-size:20px;color:red; margin-left: 20px"></i>
</label>
 <input id="fileUpload_oafileUpload" onchange="myFunction()" name="image" type="file">
</div>

 <!-- <input class="fa fa-file-photo-o" type="file" name="image">-->
<br / >
 <button type="submit" name="post" class="btn btn-success">Հաստատել</button>
</form>



the <script>
document.getElementById("fileUpload_oafileUpload").addEventListener("change",
 function (e) {
 document.getElementById("DescriptionNew").value = this.files[0].name;
});
 </script>
June 14th 19 at 20:38
take the first argument in quotes
this regexp - Howell commented on June 14th 19 at 20:41
driving your code in any ide and you will see the error. No ide at hand you can use online services to check the correct javascript syntax, for example here is the JavaScript Validator - demario.Durgan commented on June 14th 19 at 20:44
June 14th 19 at 20:40
/.*\//
thanks, but not working replace have displays image.jpg instead C:\fakepath\image.jpg - Howell commented on June 14th 19 at 20:43
, so write the correct expression and will work...In question was originally nothing about the conditions was not - demario.Durgan commented on June 14th 19 at 20:46
need the textarea displays the name of the file

<form action method="post" enctype="multipart/form-data">
 <label for="answer">Պատասխան</label>
 <div class="form-group">
 <textarea id="demo" name="answer" style="width: 100%;height: 200px;"></textarea>
 <label for="mySelect" class="custom-file-upload">
 <i class="fa fa-file-photo-o" style="font-size:20px;color:red; margin-left: 20px"></i>
</label>
 <input id="mySelect" onchange="myFunction()" name="image" type="file">
</div>

 <!-- <input class="fa fa-file-photo-o" type="file" name="image">-->
<br / >
 <button type="submit" name="post" class="btn btn-success">Հաստատել</button>
</form>

the <script>
 function myFunction() {
 var x = document.getElementById("mySelect").value;
 var y = x.replace( /.*\//, "" );
 document.getElementById("demo").innerHTML =y;

}

 </script>
- Lew.Larson commented on June 14th 19 at 20:49
later help, if nobody will give you the answer - Howell commented on June 14th 19 at 20:52
, well, well, you get the full path of the picture. You upload the file to the server and the server gives you some kind of answer here on the server side, it is necessary to edit how you want to answer. That is, you will be back or the full path or file name. There are even spike version. To take a line with your address and cut with the end of everything before the first slash. - Lew.Larson commented on June 14th 19 at 20:55
he's still nothing loads. just selected the file in the browser. - Howell commented on June 14th 19 at 20:58

Find more questions by tags JavaScript