Asked by:
how to set the physical path of dir of application to anchot tag href in div

Question
-
User-1722422105 posted
Hi all
i have anchor tag like
<a href="~/Uploads/53/Uploaded.jpg" onclick="func()" ; return false;">Open file</a> this is static
53 available in <input type="text" class="form-control" id="lbl1" readonly="readonly" />
how i can add dynamic path for anchor tag , Uploaded.jpg is again static.
folder 53 is inside Uploads, but in the solution it is shown.
Wednesday, June 27, 2018 10:05 AM
All replies
-
User475983607 posted
The HTML anchor syntax is simply. This assumes the Uploads folder is in the web application root.
<a href="/Uploads/53/Uploaded.jpg"
The tilda (~) is a server side construct not HTML.
Wednesday, June 27, 2018 10:46 AM -
User-369506445 posted
hi
I think <g class="gr_ gr_107 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="107" data-gr-id="107">your</g> mean is generated new path based input value
if yes, you can try below code :
<script src="~/Scripts/jquery-1.10.2.min.js"></script> <script> $(function () { var folderPath = "Uploads/53"; $("#lbl1").val(); $('a').each(function () { var fullpath = this.protocol + "://" + this.hostname + "/" + folderPath + this.href.replace(/^.*\/\/[^\/]+/, ''); alert(fullpath); $(this).attr('href', fullpath); }); }) </script> <a href="/Uploaded.jpg" onclick="func()" ; return false;">Open file</a> this is static <input type="text" class="form-control" id="lbl1" readonly="readonly" value="53" />
Wednesday, June 27, 2018 11:27 AM -
User-1722422105 posted
Hi Vahid thanks for reply.
my question is i have label
<input type="text" class="form-control" id="lbl1" readonly="readonly" />
we get this value dynamically. it is number, then we are creating folder programtically inside the uploads folder ,say lbl1=53 is created
inside upload, it contain the single file Uploaded.jpg so when i crearted the anchor tag href should point to \\Uploaded.jpghow we can do it
.
Wednesday, June 27, 2018 3:46 PM -
User-369506445 posted
Hi side
The last sample got label value and created a new path based on the label. But I had a mistake in the last sample, I forgot to set the label value in the path, please try below code
<script src="~/Scripts/jquery-1.10.2.min.js"></script> <script> $(function () { var folderPath = "Uploads/"+$("#lbl1").val(); $('a').each(function () { var fullpath = this.protocol + "://" + this.hostname + "/" + folderPath + this.href.replace(/^.*\/\/[^\/]+/, ''); alert(fullpath); $(this).attr('href', fullpath); }); }) </script> <a href="/Uploaded.jpg" onclick="func()" ; return false;">Open file</a> this is static <input type="text" class="form-control" id="lbl1" readonly="readonly" value="53" />
Wednesday, June 27, 2018 6:21 PM