Question Image swap from DropDownList

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
This is some HTML & Javascript for changing an image based on the users' selection in a drop-down List Box. I would like to accomplish the same thing without using Javascript. This snippet is in a View within an MVC. Is there a way this can be done through HTML exclusively or maybe replace the Javascript with some C# code ...?
VB.NET:
<img id="myImage" src="~/Content/Images/States/test.jpg" />
        
        <select id="StateSelect" onchange="setPicture(this);">
            <option value="/Content/Images/States/akPB.jpg">Arkansas</option>
            <option value="/Content/Images/States/caPB.jpg">Califonia</option>
            <option value="/Content/Images/States/coPB.jpg">Colorado</option>
            <option value="/Content/Images/States/ctPB.jpg">Conneticuit</option>
            <option value="/Content/Images/States/d.jpg">DC</option>
            <option value="/Content/Images/States/flPB.jpg">Florida</option>
        </select>

        
        <script type="text/javascript">
            function setPicture(select) {
                selectedvalue = select.value;
                document.getElementById("myImage").src = selectedvalue;
            }
        </script>
 
Last edited:
My HTML within an MVC project:
Can you confirm that the project is MVC because, if so, I will move this thread from the Web Forms forum. Web Forms and MVC are mutually exclusive alternatives.
 
Back
Top