Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > JavaScript and CSS

JavaScript and CSS Extensible Markup Language, Java Script, and CSS questions here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-07-2008, 05:46 AM
Hrimthurs Hrimthurs is offline
Newbie
 
Join Date: Jan 2008
Posts: 7
Rep Power: 0
Hrimthurs is on a distinguished road
Default Change image url with dropdown selection

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">
But I need to change parts of the url depending on the 3 chosen options on the 3 dropdowns.
HTML Code:
<img src="http://www.domain.com/images/+variable++variable2++variable3+.jpg" />
Does anyone know a way to do this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-07-2008, 07:45 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 4,862
Last Blog:
Zend Studio for Eclips...
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: Change image url with dropdown selection

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>
An easier option would be to just change the value of your select. For Example:


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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 07:56 AM
Hrimthurs Hrimthurs is offline
Newbie
 
Join Date: Jan 2008
Posts: 7
Rep Power: 0
Hrimthurs is on a distinguished road
Default Re: Change image url with dropdown selection

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">
So I'd get an out put of something like:
HTML Code:
<img name="ShowRoom" src="images/2by.jpg">
Except that script won't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 08:10 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 4,862
Last Blog:
Zend Studio for Eclips...
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: Change image url with dropdown selection

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">
Please note that I did not test this....
__________________
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 08:42 AM
Hrimthurs Hrimthurs is offline
Newbie
 
Join Date: Jan 2008
Posts: 7
Rep Power: 0
Hrimthurs is on a distinguished road
Default Re: Change image url with dropdown selection

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">
Thanks for your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 05-07-2008, 08:45 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 4,862
Last Blog:
Zend Studio for Eclips...
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: Change image url with dropdown selection

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 07:41 PM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads