Javascript Assistance

Status
This thread has been locked.

TylBur

tylburdesigns.com
Premium
Feedback score
3
Posts
244
Reactions
106
Resources
0
I am currently working on a website, using a fairly straight-forward script, however I am looking for someone who can modify the script to my needs.

What I need, is a method for any image which doesn't actually 'exist' would not appear as an option.

So, looking at the example below, it would display options 1, 2, 3, however if image 2 were not at the source location, it would not even display the option for 2.


HTML:
<select size="6" id="reportlist" class="custom-select">
<option value="">Select Option</option>
<option value="01.jpg">1</option>
<option value="02.jpg">2</option>
<option value="03.jpg">3</option>
</select>
<script>
function displayReports() {
    var img = document.getElementById("image");
    img.src = this.value;
    return false;
}
document.getElementById("reportlist").onchange = displayReports;
</script>
 
ReliableSite: Dedicated Servers

Shaun

Web Developer, owner of Syncore LLC
Supreme
Feedback score
20
Posts
627
Reactions
408
Resources
1
Simple, what you can do is check if the image exists using a Boolean operator. If it does then go ahead and use the insertAdjacentHTML method to insert HTML inside of the select tag.
 
Status
This thread has been locked.
Top
You need to upgrade!
Our dark style is reserved for our Premium members. Upgrade here.