Question Image swap from DropDownList

ALX

Well-known member
Joined
Nov 16, 2005
Messages
225
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 ...?
Code:
<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:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,203
Location
Sydney, Australia
Programming Experience
10+
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.
 

ALX

Well-known member
Joined
Nov 16, 2005
Messages
225
Location
Columbia, SC
Programming Experience
10+
Sorry... It is in fact MVC
I see now the forum for MV_
 
Top Bottom