I am wondering how I can get a javascript questionare to contain a button that posts the result onto the current users facebook wall. here is a simple version of the code I am using .. any help would be greatly appreciated.
<html>
<head>
<title>Game suggestion application</title>
<script type="text/javascript">
//This is our game list, which makes it easy to add new games
var games = [
{ name: 'Battlefield 3', type: 'fps', preference: 'tactical' },
{ name: 'Call of Duty', type: 'fps', preference: 'tactical' },
{ name: 'Starcraft', type: 'rts', preference: 'tactical' }
];
/// <summary>
/// Returns an array of game suggestions based on on the supplied type and preference
/// </summary>
function getGameSuggestions(lookingForType, lookingForPreference){
var suggestedGames = [];
//Loop through our game list and add each item which matches type and preference to our suggestion list.
for(var i = 0; i < games.length; i++){
var currentGameToCheck = games[i];
if (currentGameToCheck.type == lookingForType && currentGameToCheck.preference == lookingForPreference){
suggestedGames.push(currentGameToCheck);
}
}
return suggestedGames;
}
/// <summary>
/// Returns the value of the checked radio button for the radio button group with the supplied group name.
/// </summary>
function getRadioButtonSelectedValue(radioButtonGroupName){
//gameInfo is the name of our form object, so the document.gameInfo will give us our form element
//and in that object we should have a list of radiobuttons corresponding to the supplied name
var radioButtons = document.gameInfo[radioButtonGroupName];
//Iterate through the found buttons and return the value of the selected button
if (radioButtons && radioButtons.length){
for (var i = 0; i < radioButtons.length; i++){
if (radioButtons[i].checked)
return radioButtons[i].value;
}
}
//If no button was selected, or the radioButtonGroupName was invalid, return null.
return null;
}
/// <summary>
/// Reads the selected values and displays suggestions to the user.
/// </summary>
function suggestGame(){
//The string sent to the method needs to match the name given to the radio button elements in that group.
var type = getRadioButtonSelectedValue('type');
var preference = getRadioButtonSelectedValue('preference');
//If both type and preference was selected, alert the user of suggestions found
if (type && preference){
var suggestions = getGameSuggestions(type, preference);
if (suggestions.length == 0){
alert('No suggestions found for your selections');
}
else{
for(var i = 0; i < suggestions.length; i++){
alert('Game suggested: ' + suggestions[i].name);
}
}
}
}
</script>
</head>
<body>
<fieldset>
<legend>Game suggestions</legend>
<form name="gameInfo">
<div>
<div>Choose game type</div>
<input type="radio" name="type" value="fps">FPS</input>
<input type="radio" name="type" value="rts">RTS</input>
<input type="radio" name="type" value="rpg">RPG</input>
</div>
<div>
<div>Choose preference</div>
<input type="radio" name="preference" value="tactical">Tactical</input>
<input type="radio" name="preference" value="arcade">Arcade</input>
<input type="radio" name="preference" value="offline">Offline</input>
</div>
<input type="button" value="Suggest game!" onclick="suggestGame();"/>
</form>
</fieldset>
</body>
</html>
I am going to be brutally honest here.. I don't know where to start with the code above :(. I am at home with c# but anything to do with the web and I am in the dark :(
Member
5 Points
16 Posts
Javascript Facebook Intergration
Mar 26, 2012 04:38 AM|adammint7|LINK
Hi guys
I am wondering how I can get a javascript questionare to contain a button that posts the result onto the current users facebook wall. here is a simple version of the code I am using .. any help would be greatly appreciated.
Member
160 Points
57 Posts
Re: Javascript Facebook Intergration
Mar 26, 2012 06:22 AM|vbodro|LINK
Do you need a publish with popup window or automatically? If you want to do it automatically
user has to previously grand stream publish permission.
Pro ASP.NET Controls for Facebook applications, Facebook Connect, and Facebook Pages
Member
5 Points
16 Posts
Re: Javascript Facebook Intergration
Mar 26, 2012 10:02 AM|adammint7|LINK
I was thinking with a pop up... say a button within the messegebox. well thats what I had in mind
Member
160 Points
57 Posts
Re: Javascript Facebook Intergration
Mar 26, 2012 10:25 AM|vbodro|LINK
You can see page source from this page and adapt it for you application:
http://faceconn.com/demo/StreamPublishPage.php
Pro ASP.NET Controls for Facebook applications, Facebook Connect, and Facebook Pages
Member
5 Points
16 Posts
Re: Javascript Facebook Intergration
Mar 26, 2012 08:58 PM|adammint7|LINK
I am going to be brutally honest here.. I don't know where to start with the code above :(. I am at home with c# but anything to do with the web and I am in the dark :(