JavaScript - Obtaining User Interests Using Facebooks Api
Hey Guys,
I'm playing around with the facebook API with very limited knowledge of JavaScript, and I was wondering how I could use the FB social graph to extract user interests and display it on my site. I have the authentication set up, but I'm not sure how I would retrieve the interests, which is a JSON array. Here's my code so far Code: FB.api('/me', function(user) { if(user != null) { //create image variable and getting image var image = document.getElementById('image'); image.src = 'http://graph.facebook.com/' + user.id + '/picture'; //create name variable and getting name var name = document.getElementById('name'); name.innerHTML = user.name var movies = document.getElementById("movies"); } }); I'm not sure how I would get the movies and display the information- I know what I did isn't right since "movies" is an array... Any help is appreciated. Thanks! Similar TutorialsGood evening! After spending the last few days wrecking my brain over a simple JavaScript quiz I decided it was time I asked for help. The complete code is right beneath this post. The page will display brief instructions followed by a table containing the quiz. I'm having two rather peculiar problems. The first is with the Score() function which reads as follows: function Score(){ for(i=1;i<=10;i++) if(ans[i]== yourAns[i]) score++; prequiz.score.value= score; } Now unless I'm mistaken (which I am since the score isn't being tabulated correctly) this function essentially uses a for to cycle through both arrays, comparing the user's input against the array containing the right answers. If the contents within index i are the same on both arrays the score increases by one point. Once it cycles through the arrays, it passes score over to prequiz.score.value which will later pass this number to the text box that will display the grade to the user. The problem I'm experiencing is that the score will either be stuck at 2 or will display as 9 (even though all 10 answers were correct). Steps I've taken to try to solve this: Thinking it was the setAnsArray(question, answer) function I added a document.writeline to it. However it showed that the values were being passed correctly to the answer array. Added a document.writeline to the Score() function. Unlike the point above, score always displays as 00000 regardless of how many right answers I provide. The second issue I'm having is that the reset button is not working correctly. If I hit reset and answer the first question, the score will come back as double the score displayed before. Any insight into what is causing this issue is greatly appreciated! Code: <?xml version="1.0" encoding= "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns= "http://www.w3.org/1999/xhtml"> <head> <title>Pre-Quiz!</title> <script type="text/JavaScript"> var ans= new Array(10); var yourAns= new Array(10); var score= 0; ans[0] = "b"; ans[1] = "c"; ans[2] = "c"; ans[3] = "a"; ans[4] = "d"; ans[5] = "c"; ans[6] = "c"; ans[7] = "a"; ans[8] = "b"; ans[9] = "c"; function setAnsArray(question, answer) { yourAns[question]= answer; } function Score(){ for(i=1;i<=10;i++) if(ans[i]== yourAns[i]) score++; prequiz.score.value= score; } </script> </head> <body> <h1>Pre-Quiz</h1> <p>The following test will allow you to evaluate your knowledge in programming prior to starting the course. After completing the test you will receive a score. Should you have any further doubts feel free to bring them with you on the first day of class.</p> </body> <form name="prequiz" action="JavaScript:Score()"> <center> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value= "Reset" /><br><br> </center> <b>Sco </b><input type="text" name="score" disabled=true><br> <hr> <center><table border="3" width="65%" summary= "Questions and options are organized in a table."> <thead> <tr> <th>Question</th> <th>Options</th> </tr> </thead> <tbody> <tr> <td><b>1. The following parameter code is used in which control structure?</b><br> (int i=0; i<= size; i++)<br> </td> <td><input type="radio" name="q1" value="a" onClick="setAnsArray(1, this.value)">a. If<br> <input type="radio" name="q1" value="b" onClick="setAnsArray(1, this.value)">b. For<br> <input type="radio" name="q1" value="c" onClick="setAnsArray(1, this.value)">c. Do-while<br> <input type="radio" name="q1" value="d" onClick="setAnsArray(1, this.value)">d. While</td> </tr> <tr> <td><b>2. What does the command "cout" do?</b><br></td> <td><input type="radio" name="q2" value="a" onClick="setAnsArray(2, this.value)">a. Obtains information from the user.<br> <input type="radio" name="q2" value="b" onClick="setAnsArray(2, this.value)">b. Closes the window.<br> <input type="radio" name="q2" value="c" onClick="setAnsArray(2, this.value)">c. Displays on screen.<br> <input type="radio" name="q2" value="d" onClick="setAnsArray(2, this.value)">d. Pauses a process.</td> </tr> <tr> <td><b>3. What is the origin of name Python? (referring to the programming language)</b><br></td> <td><input type="radio" name="q3" value="a" onClick="setAnsArray(3, this.value)">a. Creator had a pet python.<br> <input type="radio" name="q3" value="b" onClick="setAnsArray(3, this.value)">b. Named after a student of Plato.<br> <input type="radio" name="q3" value="c" onClick="setAnsArray(3, this.value)">c. Named after Monty Python's Flying Circus.<br> <input type="radio" name="q3" value="d" onClick="setAnsArray(3, this.value)">d. Creator was a fan of Greek mythology.</td> </tr> <tr> <td><b>4. What does HTML stand for?</b><br></td> <td><input type="radio" name="q4" value="a" onClick="setAnsArray(4, this.value)">a. HyperText Markup Language<br> <input type="radio" name="q4" value="b" onClick="setAnsArray(4, this.value)">b. Hyper Tools for Managing Languages<br> <input type="radio" name="q4" value="c" onClick="setAnsArray(4, this.value)">c. Heap Text Manager Lead<br> <input type="radio" name="q4" value="d" onClick="setAnsArray(4, this.value)">d. Horde Take Much Lore</td> </tr> <tr> <td><b>5. Who invented JavaScript?</b><br></td> <td><input type="radio" name="q5" value="a" onClick="setAnsArray(5, this.value)">a. Bill Gates<br> <input type="radio" name="q5" value="b" onClick="setAnsArray(5, this.value)">b. Isaac Newton<br> <input type="radio" name="q5" value="c" onClick="setAnsArray(5, this.value)">c. Elvis Java<br> <input type="radio" name="q5" value="d" onClick="setAnsArray(5, this.value)">d. Netscape</td> </tr> <tr> <td><b>6. What is a variable?</b><br></td> <td><input type="radio" name="q6" value="a" onClick="setAnsArray(6, this.value)">a. An unknown.<br> <input type="radio" name="q6" value="b" onClick="setAnsArray(6, this.value)">b. A value that changes.<br> <input type="radio" name="q6" value="c" onClick="setAnsArray(6, this.value)">c. The name for a place in the computer's memory where a certain data is stored.<br> <input type="radio" name="q6" value="d" onClick="setAnsArray(6, this.value)">d. Part of an algebraic expression.</td> </tr> <tr> <td><b>7. What is a compiler?</b><br></td> <td><input type="radio" name="q7" value="a" onClick="setAnsArray(7, this.value)">a. Converts the target file into a .zip .<br> <input type="radio" name="q7" value="b" onClick="setAnsArray(7, this.value)">b. Gathers all documents in one.<br> <input type="radio" name="q7" value="c" onClick="setAnsArray(7, this.value)">c. A program or set of programs that transforms source code from programming language into another computer language.<br> <input type="radio" name="q7" value="d" onClick="setAnsArray(7, this.value)">d. Secret ingridient in KFC's chicken</td> </tr> <tr> <td><b>8. Define portability:</b><br></td> <td><input type="radio" name="q8" value="a" onClick="setAnsArray(8, this.value)">a. Characteristic attributed to a program if it can be used in another OS different from the one it was created in without requiring major rework.<br> <input type="radio" name="q8" value="b" onClick="setAnsArray(8, this.value)">b. Ease to transport the program's disks.<br> <input type="radio" name="q8" value="c" onClick="setAnsArray(8, this.value)">c. How big the size of the program is.<br> <input type="radio" name="q8" value="d" onClick="setAnsArray(8, this.value)">d. Time required to download a program.</td> </tr> <tr> <td><b>9. What is an executable file?</b><br></td> <td><input type="radio" name="q9" value="a" onClick="setAnsArray(9, this.value)">a. A text document containing code.<br> <input type="radio" name="q9" value="b" onClick="setAnsArray(9, this.value)">b. A file in a format the computar can directly execute.<br> <input type="radio" name="q9" value="c" onClick="setAnsArray(9, this.value)">c. A virus.<br> <input type="radio" name="q9" value="d" onClick="setAnsArray(9, this.value)">d. A malicious program.</td> </tr> <tr> <td><b>10. Which of the following is not a programming language? </b><br></td> <td><input type="radio" name="q10" value="a" onClick="setAnsArray(10, this.value)">a. HTML<br> <input type="radio" name="q10" value="b" onClick="setAnsArray(10, this.value)">b. Lua<br> <input type="radio" name="q10" value="c" onClick="setAnsArray(10, this.value)">c. Moolah<br> <input type="radio" name="q10" value="d" onClick="setAnsArray(10, this.value)">d. C++</td> </tr> </tbody> </table></center> </form> </html> Hi all, I have been searching for a long time to obtain the UNC path of a file using the FileUpload control using javascript.. Is there any way to obtain it. Can anyone please guide me to the answer. Thank you, Aswin How do I retrieve input/selections from this calendar widget on this site: moongarm.99k.org
Hello. Is it possible to use java script to direct users to different page depending on their username login and password? And if so, what is the script? The website i am creating is for a conference my school is hosting. What I want to do is give the username and password for each delegation to use; once they log in, they will be directed to a page which contains information pertaining only to their delegation. Right now, this is the script I have, but it only directs to one page, which is "user1.php". I want to be able to direct user2 to user2.php, user3 to user3.php and so on. <?php $usernames = array("user1", "user2", "user3", "superman"); $passwords = array("pass1", "pass2", "password3", "supermans password"); $page = "user1.php" for($i=0;$i<count($usernames);$i++){ $logindata[$usernames[$i]]=$passwords[$i]; } if($logindata[$_POST["username"]]==$_POST["password"]){ session_start(); $_SESSION["username"]=$_POST["username"]; header('Location: '.$page); exit; }else{ header('Location: login.php?wrong=1'); exit; } ?> Any help would be greatly appreciated. Thanks! Hey, so i've been learning basics and I can get the following code to work as a prompt and I thought hey, I wounder if I can get it to work of a UI system, so I edited the code and got this Read Below Post Can you please help me to find where I am going wrong. Thanks MancunianMacca Is there any possible way for JS to save changes that a user has made? my situation is that I'm a photographer who offers photobooks. My customers often have hundreds or thousands of photos and want captions on lots of them. I want to post a photo gallery with a user input form. I've created a simple form, but I want the user to be able to save comments straight to the gallery so I can look at them... it's only a very simple form and isn't quite finished yet, oh by the way, I'm not sure how to use the check box... but, i'll work on that. Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> <!-- #divWrapper { text-align: center; width: 430px; margin-right: auto; margin-left: auto; } --> </style> </head> <body> <script type="text/javascript"> function picForm() { if(document.frmInput.addPic.value="yes") { document.frmOutput.outChoice.value="will" } else { document.frmOutput.outChoice.value="will NOT" } document.frmOutput.outCap.value=document.frmInput.addCap.value; document.frmOutput.outComm.value=document.frmInput.addComm.value; } </script> <div id="divWrapper"> <p>Uncheck the box if you do NOT want this photo to appear in your photobook. Please write your caption in the box provided. Any further comments you wish to make can be entered in the second box.</p> <div id="divInput"> <form name="frmInput"> <table id="tblForm" cellpadding="3px"> <tr> <td><input name="addPic" type="checkbox" value="yes"> Add to Photobook</td> <td> </td> </tr> <tr> <td>Caption<br> <textarea name="addCap" cols="24" rows="3" value="...Add Caption Here..."></textarea></td> <td>Comments<br> <textarea name="addComm" cols="24" rows="3" value="...Add Comments Here..."></textarea></td> </tr> <tr> <td></td> <td><div align="right"> <input name="btnSubmit" type="button" value="Submit" onClick="picForm()" /> </div></td> </tr> </table> </form> </div> <div id="divOutput"> <form name="frmOutput"> <p>This photo <input name="outChoice" type="text" value="" size="7" style="border:0px" /> appear in your photo book.</p> <p>You would like the caption to read: <input name="outCap" type="text" value="" size="50" style="border:0px" /> </p> <p>Your comments to us a <input name="outComm" type="text" value="" size="50" style="border:0px" /> </p> </form> </div> </div> </body> </html> Please help! Hello all, I would like to implement a cookie feature on my site that when a user logs in a cookie is stored for him and the next time he comes back, he doesn't have to sign in. I have researched hotscripts and javascripts but the ones I have found have to do with the "remember me" and thats not quite what I want. I tried to manipulate it but with no luck. Any help with either posting code or an article would be greatly appreciated! Thanks a bunch-Dan can anyone tell me how to use jquery with asp.net web user control? Thanks in Advance Regards Salman Ansari Hi all, I have been working on a map, which now works and highlights and shows the location name on mouseover. I am having problems with how to go about getting users to be able to click on a region of the map, and depending on which region is clicked, to populate a drop down list which will appear on the same page. Then, the option which is chosen from the drop down list, would populate a blank field for the user- eg. preferences 1 - 4. The next location, would populate another drop down list, and the chosen option would populate the next blank field, if the previous one is already filled. This is what I have for the drop down lists, where the drop down is only populated from "location" array and need to somehow incorporate other array lists "locationsSouth" , "LocationsEast" and others if they were chosen. Code: <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <html> <head> <title>Drop down box</title> <script language="javascript"> function addOption(selectbox,text,value ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); } function addOption_list(selectbox){ var location = new Array("location1","location2","location3"); var locationsSouth = new Array("location1.1","location2.1","location3.1") var locationsEast = new Array ("location1.2","location2.2","location3.2") for (var i=0; i < location.length;++i){ // addOption(document.drop_list.Location_list, location[i], location[i]); // } } </script> </head> <body onLoad="addOption_list()";> Preferences <br><br> <FORM name="drop_list" action="yourpage.php" method="POST" > <SELECT NAME="Location_list"> <Option value="" >Far North</option> </SELECT> </form> </td></tr></table><div> </body> </html> This is the format of the areas of the map Code: <AREA onmouseover=changeImage(pic12); onmouseout=changeImage(pic13); shape=POLY target=_self alt="Mid North" COORDS="276,203, 284,214, 289,217, 285,267, 274,267, 257,265, 254,263, 241,291, 222,293, 229,284, 238,280, 245,249, 250,236, 253,230, 253,210, 266,201" href="section.asp?regionID=12"> I hope this made sense; I'm still trying to think about how to tackle the problem myself. Hey everybody, what regular expression do i have to use to get the 2 last elements of a user agent? eg in firefox how can i get : Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 Firefox & 7.01 ? thanks! So with the below form if the value of any of the select list changes the user is alerted something like "You are about to make 2 changes". How can I do this? Code: <script> function validate(){ } </script> <form method="POST" onsubmit="return validate()" action="--WEBBOT-SELF--"> <select size="1" name="fruits[]"> <option value="apple">apple</option> <option value="pear">pear</option> <option value="orange">orange</option> </select> <select size="1" name="cars[]"> <option value="ford">ford</option> <option value="gm">gm</option> <option value="toyota">toyota</option> </select> <input type="submit" value="Submit" name="B1"></p> </form> So I have been working on this exercise for about a month. In the book I am reading it say's this:"For each number that the user enters, the text boxes on the web page should display: the last score that was entered, the number of scores that have been entered, the total of these scores, the average score, the best score, and the worst score. When you write the code for this function, you should enclose the prompt method within a loop, but you decide which type of loop is best for this application. Now, write and test the code." The first peice of code is my HTML, and the second piece of code is the function that I have to start from in a .js file. I just seem to be confused at how my structuring needs to be. The 999 in the function is what the prompt says to enter to escape. Code: <body> <div id="content"> <h1>Using Loops</h1> <label for="lastScore">Last Sco </label> <input type="text" id="lastScore" /><br /> <p></p> <label for="scoreCount">Score Count:</label> <input type="text" id="scoreCount" /><br /> <label for="scoreTotal">Score Total:</label> <input type="text" id="scoreTotal" /><br /> <p></p> <label for="scoreAverage">Average Sco </label> <input type="text" id="scoreAverage" /><br /> <label for="bestScore">Best Sco </label> <input type="text" id="bestScore" /><br /> <label for="worstScore">Worst Sco </label> <input type="text" id="worstScore" /><br /> <p></p> </div> Code: var process_test_scores = function () { var testScore; testScore = parseInt(prompt( "Enter a valid test score between 0 and 100.\n" + "To end test score entry, enter 999.", 999)); } In a normal chatroom, when the user "says" something, the text will be displayed normally on a line with the date/time attached like the example below. 2011/11/09 Capypara: Blah balh blah I would like to make it so that the text typed in by the user will appear inside a graphic (square, or those chat bubbles) like the example below. The graphic will only appear when a user says something, so essentially both the graphic and the text will appear together. ~~~~~~~~~~~~~~~~~~~~~~~~ | | | 2011/11/09 Capypara: Blah balh blah | | | ~~~~~~~~~~~~~~~~~~~~~~~~ Is it possible to go about doing this? Thanks for reading this. _________
Hello all, First off I would like to say a big hello and thank you to the forum for helping me with code over the years... I am trying to create an iframe with a user input, however, I dont simply want the iframe to display the URL the user has entered in the iframe. I want it to be used within a URL string. For example: The iframe should display http://www.google.co.uk/search?q=UserKeyword I havent got a clue where to start from.... Any help would be highly appreciated! Thanks! In my onbeforeunload event, it asked the user whether they want to leave the page or stay on it. When they click "stay on page", I want it to then redirect them to another webpage in the same window. Is there a way to do this, without just showing/hiding divs? Can I override the function? I'm currently trying to do it this way(as seen below) but now the dialog box is not showing up at all. It was working before Any ideas as to what I'm doing wrong, or how to accomplish this task? Code: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>The Shocking Truth - Cabot Market Letter</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#vid").show(); $("#div2").hide(); }); var test = 1; function manipulatetest() { test = 2; } window.onbeforeunload = onbeforeunload_Handler; function onbeforeunload_Handler() { if (test == 1){ $("#vid").hide(); $("#div2").show(); var confirm = confirm("Would you like to stay on this page?"); if (confirm == true) { window.location = "http://www.google.com"; } } } </script> </head> <style type="text/css"> body { background-color: #e0e6e5; } #vid { margin: 20px auto; width: 920px; } </style> <body> <div id="vid"> <video width="920" height="540" autoplay preload controls> <source src="shockingtruth.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> <source src="shockingtruth.webm" type='video/webm; codecs="vp8, vorbis"'> <source src="shockingtruth.ogv" type='video/ogg; codecs="theora, vorbis"'> <object width="920" height="540" type="application/x-shockwave-flash" data="flowplayer-3.2.1.swf"> <param name="movie" value="flowplayer-3.2.7.swf" /> <param name="allowfullscreen" value="true" /> <param name="flashvars" value='config={"clip": {"url": "http://www.cabot.net/videos/shocking-truth/shockingtruth.mp4", "autoPlay":true, "autoBuffering":true}}' /> <p>Download video as <a href="pr6.mp4">MP4</a>, <a href="pr6.webm">WebM</a>, or <a href="pr6.ogv">Ogg</a>.</p> </object> </video> </div> <div id="div2"> <video width="920" height="540" autoplay preload controls> <source src="shockingtruth.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> <source src="shockingtruth.webm" type='video/webm; codecs="vp8, vorbis"'> <source src="shockingtruth.ogv" type='video/ogg; codecs="theora, vorbis"'> <object width="920" height="540" type="application/x-shockwave-flash" data="flowplayer-3.2.1.swf"> <param name="movie" value="flowplayer-3.2.7.swf" /> <param name="allowfullscreen" value="true" /> <param name="flashvars" value='config={"clip": {"url": "http://www.cabot.net/videos/shocking-truth/shockingtruth.mp4", "autoPlay":true, "autoBuffering":true}}' /> <p>Download video as <a href="pr6.mp4">MP4</a>, <a href="pr6.webm">WebM</a>, or <a href="pr6.ogv">Ogg</a>.</p> </object> </video> </div> <p style="text-align: center;"><a href="http://www.cabot.net/info/cml/cmlld03.aspx?source=ed01" onclick="manipulatetest();">Click Here To Order</a></p> </body> </html> Code: <?php if($_SESSION['id']) echo '<h1>Hello, '.$_SESSION['usr'].'! You are registered and logged in!</h1>'; else echo '<h1>Please, <a href="demo.php">login</a> and come back later!</h1>'; echo 'Should i find a new login' ?> im trying to use this as a check to see if someone is logged in, is this the right idea, any tips to improve this or anymore info just ask please Thanks I'm trying to make a similar form to what Craigslist uses where you can mail to a user provided email and make it look like it came from whatever email address the user provides. I've looked at the code from the Craigslist page and can't seem to find the correct program they are using. I've been out of the game for a while and saying my coding is rusty is an understatement. Any help would be appreciated. hi i am using apache htpasswd basic authentication password file. my web site is working well. when i give url in browser a dialogue box will appear for user id and password and in case of correct userid and password, home page of my web site opens. but problem is, i have more then one users and i want to get user id, who log in and I wants to print user id on home page at run time in java script because my web site is simple html web site. it is not form base authentication so how is possible to get user id. kindly help me . thanks and regards, Muhammad Akmal |