|
||||||
| JavaScript and CSS Extensible Markup Language, Java Script, and CSS questions here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi there,
I am currently trying to find out how to alter parts of an image url through the selection of a dropdown. I have something where the first dropdown changes the entire url: HTML Code:
<script language="javascript"> <!-- function ShowPic(sImage) { document.ShowRoom.src = sImage; } // --> </script> <form name="proof"> <select name="design" onChange="ShowPic(this.value)"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> <select name="style"> <option value="a">Option a</option> <option value="b">Option b</option> </select> <select name="finish"> <option value="z">Option z</option> <option value="y">Option y</option> </select> </form> <img name="ShowRoom" src="images/outsidefront.jpg"> HTML Code:
<img src="http://www.domain.com/images/+variable++variable2++variable3+.jpg" />
|
| Sponsored Links |
|
|
|
|||||
|
So right now when a user clicks on option 2 your ShowPic() function is executed. Which then assigns the value of the selection to a variable and changes the ShowRoom picture. The problem is the value is 2. So
>> Clicks 2 ShowPic(2); document.ShowRoom.src = 2 URL of picture = 2. Basically you just need to append the "images/variableXX.jpg" to the src. Here is how: Code:
<script language="javascript">
<!--
function ShowPic(sImage)
{
document.ShowRoom.src = "images/variable" + sImage + ".jpg";
}
// -->
</script>
Code:
<option value="images/variable1.jpg">Option 1</option>
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
|
|||
|
Wow, thanks.
That solved an issue I didn't think about. What I need to do now is something like the following. HTML Code:
<script language="javascript"> <!-- function ShowPic(sImage) { function ShowPic2(sImage2) { function ShowPic3(sImage3) { document.ShowRoom.src = "images/variable" + sImage + sImage2 + sImage3 + ".jpg"; } } } // --> </script> <form name="proof"> <select name="design" onChange="ShowPic(this.value)"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> <select name="style" onChange="ShowPic2(this.value)"> <option value="a">Option a</option> <option value="b">Option b</option> </select> <select name="finish" onChange="ShowPic3(this.value)"> <option value="z">Option z</option> <option value="y">Option y</option> </select> </form> <img name="ShowRoom" src="images/1az.jpg"> HTML Code:
<img name="ShowRoom" src="images/2by.jpg">
|
|
|||||
|
Here is an easier way to do what you want:
HTML Code:
<script language="javascript"> <!-- function ShowPic() { // Get the select values var design = document.proof.design.options[document.proof.design.selectedIndex].value; var style = document.proof.style.options[document.proof.style.selectedIndex].value; var finish = document.proof.finish.options[document.finish.design.selectedIndex].value; // Create our Image var sImage = "http://forum.codecall.net/images/variable" + design + style + finish + ".jpg"; // Assign the image document.ShowRoom.src = sImage; } // --> </script> <form name="proof"> <select name="design" onChange="ShowPic()"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> <select name="style" onChange="ShowPic()"> <option value="a">Option a</option> <option value="b">Option b</option> </select> <select name="finish" onChange="ShowPic()"> <option value="z">Option z</option> <option value="y">Option y</option> </select> </form> <img name="ShowRoom" src="http://forum.codecall.net/images/1az.jpg">
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
|
|||
|
Thanks!
I've tweaked that a bit and got it working perfectly. HTML Code:
<script language="javascript"> <!-- function ShowPic(sImage) { // Get the select values var design = document.proof.design.options[document.proof.design.selectedIndex].value; var style = document.proof.style.options[document.proof.style.selectedIndex].value; var finish = document.proof.finish.options[document.proof.finish.selectedIndex].value; // Create our Image var sImage = "images/" + design + style + finish + ".jpg"; // Assign the image document.ShowRoom.src = sImage; } // --> </script> <form name="proof"> <select name="design" onChange="ShowPic()"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> <select name="style" onChange="ShowPic()"> <option value="a">Option a</option> <option value="b">Option b</option> </select> <select name="finish" onChange="ShowPic()"> <option value="z">Option z</option> <option value="y">Option y</option> </select> </form> <img name="ShowRoom" src="images/1az.jpg"> |
| Sponsored Links |
|
|
|
|||||
|
I see, I'm not sure how "http://forum.codecall.net/images/" got into the sImage variable but I am glad it works! Feel free to post any more questions you have.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with image upload script - need to make an if null statement | norbie | PHP Forum | 7 | 05-04-2008 09:44 AM |
| Change image help | wilk3sy | JavaScript and CSS | 3 | 12-19-2007 05:45 AM |
| JavaScript:Tutorial, MouseOver Image Change | TcM | Javascript | 2 | 10-30-2007 01:51 PM |
| Resize Images And Maintain Original Sharpness | AfTriX | Photoshop Tutorials | 7 | 04-20-2007 09:55 AM |
| Using change management | Cosmet | General Programming | 2 | 10-30-2006 06:16 PM |