kucing Posted February 24, 2007 Share Posted February 24, 2007 Dear friends, I have search google and tested many examples and I found non of them working for me.. So now I need your help to solve this thing.. Actually what I wanted to do was save one value from javascript to my database but when doing that I don't want my page to refreash and also don't want any button asking me to submit then save! Any thing will be best which do it automaticaly without clicking anywhere also could be ajax thing. Or also if possible sending that value directly to $_SESSION will be best. Here is my code example. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Java2php Test</title> <script type="text/javascript"> var N=5; var array = new Array() var items = list.getElementsByTagName("li") for (var i = 0, n = N; i < n; i++) { var item = items[i] array.push(myFnc(item)) } alert(array); // <----- i want this array to forward to my php script return array.join('|') </script> </head> <body> <ul id="menu"> <li class="box" id=1>TEST1</li> <li class="box" id=2>TEST2</li> <li class="box" id=3>TEST3</li> <li class="box" id=4>TEST4</li> <li class="box" id=5>TEST5</li> <li class="box" id=6>TEST6</li> <li class="box" id=7>TEST7</li> <li class="box" id=8>TEST8</li> <li class="box" id=9>TEST9</li> <li class="box" id=10>TEST10</li> </ul> </body> </html> Thanks Any help is very much appreciated K Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 You'll have to use AJAX - check out mootools. Quote Link to comment Share on other sites More sharing options...
kucing Posted February 24, 2007 Author Share Posted February 24, 2007 Jesirose very thanks for a very quick response. I also want to mention that I already have many .js running at a time and if I add one more .js file my site is really gonnd be very slow So i was looking forward for a way which doesn't involve some complex but a easy way to pass a variable to php without my page get refreash. Thanks again K Quote Link to comment Share on other sites More sharing options...
kucing Posted February 24, 2007 Author Share Posted February 24, 2007 Any more hints for me Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 Then you need to clean up your javascript, honestly. If your javascript files are so big that it slows down the site, you need to move all of your JS into one file, and possibly even compress it. The mootools framework is a very light one which is really great, so I think it could help with all your JS. Quote Link to comment Share on other sites More sharing options...
kucing Posted February 24, 2007 Author Share Posted February 24, 2007 Thanks all for listening me. And my issue is now solved as I found something very cool no ajax an it's not even longer than one line and atlast I manage to pass the data directly to $_SESSION Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 And how did you do that with javascript? Quote Link to comment Share on other sites More sharing options...
kucing Posted February 24, 2007 Author Share Posted February 24, 2007 Here how I did that <script type="text/javascript"> var N=5; var array = new Array() var items = list.getElementsByTagName("li") for (var i = 0, n = N; i < n; i++) { var item = items[i] array.push(myFnc(item)) } alert(array); // <----- i want this array to forward to my php script saveIT.innerHTML = '<IFRAME src="myTest.php?lid='+array+'" width="300" height="200" frameborder="0"></IFRAME>'; return array.join('|') } </script> So this little thing saved my another 2 days.. lol saveIT.innerHTML = '<IFRAME src="myTest.php?lid='+array+'" width="300" height="200" frameborder="0"></IFRAME>'; <div id="saveIT"></div> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.