Passing from image Array in url

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Oct 2009
Posts: 8
Reputation: darkRoom is an unknown quantity at this point 
Solved Threads: 0
darkRoom darkRoom is offline Offline
Newbie Poster

Passing from image Array in url

 
0
  #1
Oct 17th, 2009
My website I'm building has various image Arrays, I have JS code passing data so an image in 1st page exp:[image5] loads into 2nd pages Array as [image5], it works in all browsers except Firefox where 1st page reloads to [image1] in 1st page Array. Being a newbie I can't seem to work around issue any suggestions are greatly appreciated!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #2
Oct 19th, 2009
DarkRoom,

There's not a lot to go on there.

For a diagnosis, you will have to post some actual code.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: darkRoom is an unknown quantity at this point 
Solved Threads: 0
darkRoom darkRoom is offline Offline
Newbie Poster

What to send

 
0
  #3
Oct 19th, 2009
Originally Posted by Airshow View Post
DarkRoom,

There's not a lot to go on there.

For a diagnosis, you will have to post some actual code.

Airshow
Thank you for replying being new not really sure how much or which parts of code to submit for you to get an idea of the issue.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: darkRoom is an unknown quantity at this point 
Solved Threads: 0
darkRoom darkRoom is offline Offline
Newbie Poster
 
0
  #4
Oct 20th, 2009
Hope this is what your looking for.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <head>
  2. <script type="javascript/text">
  3. function zoom()
  4. {
  5. document.location.replace("stevenbroadypfpaexl4.html?jss="+jss);
  6. }
  7. </script>
  8. </head>
  9. <body>
  10. <FORM NAME="passed">
  11. <INPUT TYPE="hidden" NAME="variable" SIZE="35">
  12. </FORM>
  13. <div id="apDiv1"><img src="images/P1s.jpg" name=PictureBox width=656 height=429 /></div>
  14. <script type="text/javascript">
  15.  
  16. document.passed.variable.value = window.location
  17. var number = document.passed.variable.value
  18.  
  19. function delineate(str){
  20. theleft = str.indexOf("=") + 1;
  21. theright = str.length;
  22. if(theleft)
  23. {
  24. return Number(str.substring(theleft, theright));
  25. }
  26. else
  27. {
  28. return(1);
  29. }
  30. }
  31. jss=delineate(number);
  32. PictureBox.src=Picture[jss]
  33.  
  34. </script>
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #5
Oct 20th, 2009
darkRoom,

Put this in document head (replacing current script):
  1. <script type="javascript/text">
  2. function QueryParser(str) {
  3. /******************** Query Parser *********************
  4.   ***** A general purpose querysrting parser/builder ****
  5.   ********************* by Airshow **********************
  6.   ********* Please keep this attribution intact *********/
  7. if (str) {
  8. str = unescape(str);
  9. if (str.indexOf("?") === 0) { str = str.substring(1); }
  10. var args = str.split("&");
  11. for (var i = 0; i < args.length; i++) {
  12. var pair = args[i].split("=");
  13. if (pair.length >= 1) {
  14. var prop = pair.shift();
  15. this[prop] = (pair.length == 1) ? pair[0] : (pair.length > 1) ? pair.join('=') : '';
  16. }
  17. }
  18. }
  19. this.set = function (prop, value) { return this[prop] = value; };
  20. this.clear = function (prop) {
  21. if(typeof this[prop] !== 'undefined') {
  22. this.set(prop, null);
  23. return true;
  24. }
  25. else { return false; }
  26. };
  27. this.build = function (baseURL) {
  28. baseURL = (!baseURL || typeof baseURL !== 'string') ? '' : (baseURL.indexOf("?") === -1) ? (baseURL + '?') : baseURL;
  29. var strArray = [];
  30. for (var prop in this) {
  31. if (typeof this[prop] !== 'undefined' && typeof this[prop] !== 'function' && this[prop] !== null) { strArray.push([prop, '=', this[prop]].join('')); }
  32. }
  33. return baseURL + strArray.join('&');
  34. };
  35. this.buildLink = function (baseURL, linkTxt) {
  36. var url = this.build(baseURL);
  37. return [ '<a href="', url, '">', ((!linkTxt) ? url : linkTxt), '</a>' ].join('');
  38. };
  39. }
  40. var $q = new QueryParser(location.search);
  41.  
  42. function zoom(jss){
  43. // jss argumant is optional;
  44. // if not passed, the existing value of $q.jss is used to build the new url
  45. // if passed, the value of $q.jss is set to this value and used to build the new url
  46. if(jss) { $q.set('jss', jss); }
  47. document.location.replace($q.build('stevenbroadypfpaexl4.html');
  48. }
  49.  
  50. onload = function(){
  51. //This will run as soon as the page is loaded
  52. var p = document.getElementById('PictureBox');
  53. if(p && $q.jss){ PictureBox.src = Picture[$q.jss]; }
  54. }
  55. </script>
Then delete the script in the document body.

Then, in the document body:
  1. //-- change
  2. <div id="apDiv1"><img src="images/P1s.jpg" name="PictureBox" width="656" height="429" /></div>
  3. //-- to
  4. <div id="apDiv1"><img src="images/P1s.jpg" id="PictureBox" width="656" height="429" /></div>
The code centres around $q, an instance of my QueryParser object, which automatically parses the querystring of the page's url and makes each parameter available as $q.paramX , $q.paramY , $q.paramZ (fictitious param names). $q also has methods to set and clear parameters individually prior to either building a url or HTML link, with querystring composed from its current properties.

If you need to build url(s)/link(s) which is comletely independent of the current page's url, then you can create further instance(s) of QueryParser .

Enjoy.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: darkRoom is an unknown quantity at this point 
Solved Threads: 0
darkRoom darkRoom is offline Offline
Newbie Poster
 
0
  #6
Oct 21st, 2009
Well I reworked document but maybe I'm missing or not understanding something, or maybe you need to see whole document to make it work. At this point with your script which seems amazing and somewhat unintelligible to this novice, I get no reaction from the button that replaces page(zoom)using onclick="QueryParser()". What I don't grasp in all of this is why in all other browsers url gets passed through <Form> but Firefox doesn't. Sorry don't mean to be a pain in the ass asking silly questions, but I really would like to understand, learn so I can do JS properly.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #7
Oct 21st, 2009
darkRoom,

Please don't worry about asking questions. Javascript is superficialy simple but hides a multidude of complexity.

The script I posted above is designed to go in your 2nd page(s) in order to receive and act on parameter(s) passed from 1st page. You may leave your 1st page as it was.

You don't need to call QueryParser as it is called by the line var $q = new QueryParser(location.search); thus making the global object $q with properties reflecting the parameters passed in the url's querystring.

For example:

Page URL : myPage2.html?name=Fred&birthday=01/01/1985&iq=110

With QueryParser, the parameters ICODE]name[/ICODE], birthday , iq become accessible in Javascript as:
  • $q.name : Fred
  • $q.birthday : 01/01/1985
  • $q.iq : 110

So this is a way to pass values from one page to another. (Other methods involve cookies or server-side scripting).

I hope this better explains how to use my code.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: darkRoom is an unknown quantity at this point 
Solved Threads: 0
darkRoom darkRoom is offline Offline
Newbie Poster
 
0
  #8
Oct 21st, 2009
I placed your script in 2 test pages (orig and enlarge) of my site so in theory it should work. I may be overreaching on construction my first site but being a retouching site it has to be technically and graphically engaging. It has 4 image example pages (about 10 images in each Array) each being able to zoom in and out (switching pages) by pressing a button(image) to allow visitors to better examine my work (it also has flash pages those I'm not worried about) by pressing zoom button new page loads either enlarged or reduced depending where you are at. I don't have my site up yet otherwise I would send a visual which may help not sure how else to facilitate your trying to solve my problem.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: darkRoom is an unknown quantity at this point 
Solved Threads: 0
darkRoom darkRoom is offline Offline
Newbie Poster
 
0
  #9
Oct 23rd, 2009
Ok so I got half my problem solved by adding return false; in the head script and return before onclick to the button .it will open proper page but won't pass array data
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #10
Oct 23rd, 2009
darkRoom,

I will see if I can find time to make a two-page demo showing how to use the code.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1094 | Replies: 12
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC