![]() |
variable transfer from js to PHP
This is somewhat related to jquery but is primarily a .js issue.
I am converting an existing PHP photo album. I have the image load working but can't see how to get the respective caption key from the js to pull from $caption_array. This is the code I am using - where the div class=change is actually a string of thumbnails each with the ID set as the filename. Click one and the div class=bg-wrapper is loaded with the main image. Code:
<div class=change>thumb(s)</div>thanks |
I have done the proverbial googling and a common response is "can't be done without page reload".
BUT... is there a glimmer of hope in Ajax? I know zero on this - but will look about. Any suggests along the way? |
can't you pull in caption array when the page loads, make objects that bind the image to the caption and change them both when the click happens?
|
@xelawho
I have been banging away at this over an hour now :)) And, YES, that is what I am exploring now. Code:
$captions = file($data_file); // pulled from CSV<div class=change id=tn_THUMBname>thumb(s)</div> My first thought would be to add the number on the end of the id val and do a substr thing [not sure of js equiv] Annnnnd, then I presume I would need to do a document.write ? Would it have to be inside the parent div? not dumb - just new ;] thanks |
document.write, no.
if the div that you want the caption to me in has the id 'tn_THUMBname' wouldn't it be something like Code:
$('#tn_THUMBname').text(caption_array[0]) |
scratches head.....
the issue so often is defining the question - bare with me. $data_file has all the captions - not necessarily sequential. img_cat.jpg|cat caption here pic_dog.jpg|about the dog etc. So, I will also need to split this array and loop to find the line that matches against $(this).attr("id").replace("tn_","") it feels close thx |
if your array looks like that, you could do something like this:
Code:
<script> |
or you could use the script to load the thumbnail images in at the same time...
Code:
<body> |
This looks awesome. Thanks so much.
Not sure where pics[] fits in. The main image div is wrapped in a nice frame and I am hoping to add the caption to a div below that. I have to head out now but should have time to test this later on this evening. 40+ posts since 2006 - I don't do a lot of js so am very grateful for your patience. |
oh, yeah - pics[] was from an earlier idea - I forgot to take that out - it doesn't do anything.
|
Worked a bit last night but couldn't tease out the logic of your code.
This is what I have so far - perhaps a bit 'old school' linear but it works. The alert gives the correct caption but I am unsure how to feed it into a div. The image div is #bg-wrapper but, again, I can't replicate the logic to feed my caption into another div - say: #img_caption Code:
<script>Cheers - ak |
Still poking about.
I have a FF solution but no IE Code:
<script>PS - an alert test on var len has FF=18 IE=17 - which is weird. |
Thanks fran55k.
js is such a muddle for me. Part of my issue was in the caption array itself - fixed. My issue now is testing that the caption is not empty - null string - undefined. if (file[0]==img_now && ?? ) { var this_cap = file[1]; } tried with ?? as: file[1].length>1 file[1]!=='' file[1]!==NULL file[1]!=='undefined' Fortunately the existing script is working fine. This is just my aiming to add dynamic content - not something I have much experience with. Getting into jquery and such. |
I'm sorry... it makes me sleepy just looking at your code.
You should really get at least a basic grip on javascript before branching off into jQuery. And if you need this done now, there are a million ready-written slideshow scripts out there, in javascript and jQuery... |
>> sleepy...
Mostly I hack existing js. The main code of mine above is the i loop and innerhtml. The rest is borrowed. My PHP is a tad more elegant. >> a basic grip on javascript I don't use it a lot. jquery I try to use out-of-the-box >> a million ready-written slideshow scripts Indeed. I am hoping to avoid the heavy image load that most require. Up to 100 pics at around 50kb or more takes a while. I figure most people only look at 5 to 10 images per album. I have this working well enough for now. Thanks again for your patience. arfa |
| All times are GMT +1. The time now is 08:07 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.