473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dinamic Image from parameter in URL

Hello, i know nothing about Javascript and i hope someone in the bast
net can help me resolve this, i need to show an image based on a
parameter in the url.

http://www.mysite.com/modules/news/i...hp?storytopic=[value]

Where i have numeric values to say 5 max... so if storytopic=1 shows a
diferent header as if storytopic value where 2, or 3 for example.

i got this from the web....
Expand|Select|Wrap|Line Numbers
  1.  
  2. function getURLParam(strParamName){
  3. var strReturn = "";
  4. var strHref = window.location.href;
  5. if ( strHref.indexOf("?") -1 ){
  6. var strQueryString =
  7. strHref.substr(strHref.indexOf("?")).toLowerCase();
  8. var aQueryString = strQueryString.split("&");
  9. for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
  10. if (aQueryString[iParam].indexOf(strParamName + "=") -1 ){
  11. var aParam = aQueryString[iParam].split("=");
  12. strReturn = aParam[1];
  13. break;
  14. }
  15. }
  16. }
  17. return strReturn;
  18. }
  19.  
  20.  
but im still tring to figure it out... :-$

can someone be kind enough to help me with this, that -i only assume-
must be kind of easy to someone who knows the language.

Thanks.

Rojo, DJ.
México

Aug 25 '06 #1
3 2719

me***********@gmail.com wrote:
Hello, i know nothing about Javascript and i hope someone in the bast
net can help me resolve this, i need to show an image based on a
parameter in the url.

http://www.mysite.com/modules/news/i...hp?storytopic=[value]

Where i have numeric values to say 5 max... so if storytopic=1 shows a
diferent header as if storytopic value where 2, or 3 for example.
If when your form gets submitted and your url looks exactly like the
above, then this will suffice:

function getStoryTopic()
{
var querystring = location.search;
var topic = -1;

if(querystring.length 0)
{
topic = +querystring.split("=")[1];
}

switch(topic)
{
case "1":
//show image for topic 1
break;
case "2":
//show image for topic 2
break;
case "3":
//show image for topic 2
break;
case "4":
//show image for topic 2
break;
case "5":
//show image for topic 2
break;
default:
//there was no topic
break;
}
}

Aug 25 '06 #2
*** me***********@gmail.com escribió/wrote (25 Aug 2006 15:42:19 -0700):
Hello, i know nothing about Javascript and i hope someone in the bast
net can help me resolve this, i need to show an image based on a
parameter in the url.

http://www.mysite.com/modules/news/i...hp?storytopic=[value]

Where i have numeric values to say 5 max... so if storytopic=1 shows a
diferent header as if storytopic value where 2, or 3 for example.
Untested:
<script type="text/javascript"><!--
function parseGet(variable){
var get=document.location.search.substring(1).split('& ');
for(var i=0; i<get.length; i++){
var igual=get[i].indexOf('=');
if(get[i].substring(0, igual)==variable){
return unescape(get[i].substring(igual+1));
}
}
return('');
}

var img='';
switch(parseGet('storytopic')){
case '1':
var img="foo.jpg";
break;
case '2':
var img="bar.jpg";
break:
}
if(img!=''){
document.writeln('<img src="' . img . '">');
}
//--></script>


--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 25 '06 #3
Thanks everyone.. i tried both your scripts, but as none worked for me,
most probably because i did wrong i used this and is working.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function getURLParam(strParamName){
  3. var strReturn = "";
  4. var strHref = window.location.href;
  5. if ( strHref.indexOf("?") -1 ){
  6. var strQueryString =
  7. strHref.substr(strHref.indexOf("?")).toLowerCase();
  8. var aQueryString = strQueryString.split("&");
  9. for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
  10. if (
  11. aQueryString[iParam].indexOf(strParamName + "=") -1 ){
  12. var aParam = aQueryString[iParam].split("=");
  13. strReturn = aParam[1];
  14. break;
  15. }
  16. }
  17. }
  18. return strReturn;
  19. }
  20. var topic = getURLParam("storytopic");
  21.  
  22. switch(topic)
  23. {
  24. case "1":
  25. document.writeln('<img src="image1.jpg">');
  26. break;
  27. case "2":
  28. document.writeln('<img src="image2.jpg">');
  29. break;
  30. case "3":
  31. document.writeln('<img src="image3.jpg">');
  32. break;
  33. default:
  34. document.writeln('<img src="default.jpg">');
  35. break;
  36. }
  37.  
  38.  
Very usefull to me... Thanks again for your reply's.

Gracias

Rojo, DJ.
México.

Aug 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dddddd | last post by:
i need do create simple dinamic site - built mainly of pictures(they are the only dinamic part). pictuers differ by the -Location- and by -Time- (in which they were taken)... so on the index...
3
by: Jose Garcia | last post by:
Hi there, Can somebody explain me how can i use matrixes with dinamic memory? I use malloc and free (NOT new & delete). I want to access to the matrix like Matrix but i don't know how to do that...
6
by: gp | last post by:
Hi all, I'm using Microsoft Visual C++ 6.0, I would like to see, debugging my project, all the elements of my dinamic objects.... I have a dinamic array and a STL vector and I need to know...
10
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
0
by: Damir | last post by:
Please I need help and dont know where to post the question..... So I am making a small asp.net application and need to generate a crystal report with one image that changes depending of some data....
9
by: Tom John | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
12
by: Lance | last post by:
hey all, first time vb.net 2005 user, after sticking vb6 out for a long time... anyway, using this code ====================== Dim FS As FileStream = File.OpenRead(Filename) Dim theImage As...
0
by: harshad | last post by:
Dear All,Here I am facing problem to store image.I am trying to store byte array(image) in to session variable so at time of update I will got that byte array and I do my update. here i am given...
1
by: Jorge | last post by:
On Oct 23, 10:36 am, Tuxedo <tux...@mailinator.comwrote: Yes: function first_function (PARAMETER) { preload_image = new Image(800,600); preload_image.onload = function () {...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.