Jump to content

change src value when a button is pressed


katia

Recommended Posts

Make sure that $sirpics has the information you need in it.  Do print_r($sirpics) to see the contents of it.

It seems that it doesArray ( [0] => ..\Img\album4\37e4.jpg [1] => ..\Img\album4\630e.jpg [2] => ..\Img\album4\delbanchet1.jpg [3] => ..\Img\album4\delbanchet2.JPG [4] => ..\Img\album4\DSC03627.jpg [5] => ..\Img\album4\S3010390.JPG )
Link to comment
Share on other sites

It seems that it doesArray ( [0] => ..\Img\album4\37e4.jpg [1] => ..\Img\album4\630e.jpg [2] => ..\Img\album4\delbanchet1.jpg [3] => ..\Img\album4\delbanchet2.JPG [4] => ..\Img\album4\DSC03627.jpg [5] => ..\Img\album4\S3010390.JPG )

Why do you have the javascript outwith head and body tags plus would it not make sense to move it down to where your other php gererates the array.maybe like this
<?       $nrpoza=$nrpoza;       $numepoza=$numepoza;       $album=$album;       $opendir = opendir($album);       $dim=0;      $sirpics=array();?><script type="text/javascript"><!--sir = new Array();<? while($fname=readdir($opendir))     {     $poza=$album."\\".$fname;     $a=split("\\\\\\\\",$album);      $nr=count($a)-1;       $pozanou="..\\Img\\".$a[$nr]."\\".$fname;       if (is_file($poza))        {         $sirpics[$dim]=$pozanou;[color="red"]         echo "sir[{$dim}] = \"{$sirpics[$dim]}\";\n";[/color]         $dim++;        }    }?>alert(sir[0]);--></script>

Link to comment
Share on other sites

Why do you have the javascript outwith head and body tags plus would it not make sense to move it down to where your other php gererates the array.
I keep it there because I need the result of the function when I press the "next" button. The button code is above the code where I create the array.I will work on it more tomorrow.Thank you guys for your help :)
Link to comment
Share on other sites

I keep it there because I need the result of the function when I press the "next" button. The button code is above the code where I create the array.
Ok some of this isn't making sense to me :) echo " <input type=\"button\" name=\"Submit4\" value=\"next\" onClick=\"parseArray($sirpics)\"> ";$sirpics is the value of the array of pictures loaded from the server, right?if so it means you are passing all of that info to the javascript function, which i'm pretty sure will be a string of text not an array -----------------------In this piece of code you are counting the $sirpics which hasn't been created yet as it takes place below this code, remember code executes from top to bottom (undefined error?).Then you are passing sirpics as a javascript parameter, but it's never used in the javascript code so it does nothing.function parseArray(sirpics){sir = new Array();<?phpfor ($i = 0; $i < count($sirpics); $i++)echo "sir[{$i}] = \"{$sirpics[$i]}\";\n";?>alert(sir[0]);}--></script>Like is said in the previous post i think the code has to be moved down and create the javascript array alongside the php one, then when you click on next you will have a new function which will cycle through the javascript array.
Link to comment
Share on other sites

My array contained some elements like: ..Img\album4\321dd.jpg and when I copied it to the javascript array it was all messed up because the "\" . I did put the javascript code in the place where I create the php array, I added some functions for changing the image src value and it works.Thank you guys, I really appreciate your help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...