PDA

View Full Version : New to Java and Ajax, help needed


tfnguru
03-29-2008, 05:55 PM
I am new to the world of Java programming and I am curious if one of you experts can help me possibly. My brother and I run a Fantasy sports league where we play just about most major sports, frustrated with the lack of scripts out there for fantasy sports I have decided to attemp to write a live draft script in Ajax. I am trying to learn all I can about Java programming and curious to find an expert to help me or mentor me in this project. Thanks in advance.

mjlorbet
03-29-2008, 06:15 PM
well, just for clarification, since it is such a common mistake, java and javascript are not the same nor even are they related, referring to one by the other's name only lends to confusion. as for your project, it seems that your question would be a better fit for the small projects forum since you are asking for someone to work with you on a project, not with a particular script/segment of code. if you have existing (x)html code somplace that you're looking to work some script into, that could be posted here & suggestions could be made based on that, or if you have a script partially made and need help finishing that, or if you'd post a list of things that you need a script to do we can at least walk you through with some pseudo-code. really all depends on where exactly you are in the development of this thing. if you do already have something prepared or at least partially prepared, please do either post the code or a link to the site so we can see where you're at & help based on that.

tfnguru
03-29-2008, 06:26 PM
Mike Thanks for the info I will post a list detailing what we are trying to do with this script. I will gladly give copyright to the person who writes the code. Clearly from my first post you can see I am just an art guy trying to learn about coding.

tfnguru
03-29-2008, 06:41 PM
Right now we currently only need a live draft script for NASCAR, we pick once a week about 16 races a season, 8 teams, 3 drivers per team.

All we really need is as follows

1. Clock timer to countdown current pick
2. Draft order display that rotates to show who is currently on the clock
3. Display of drivers available that removes the drivers as they are picked
4. Display of the eight teams and who they have selected updated as they are selected
5. Possibly a small chat box for people to chat as they wait on their turn

mjlorbet
03-29-2008, 08:04 PM
sounds ambitious, i'm guessing there's no actual html done yet then? if not, the small to medium projects section would certainly be your best bet, of course assuming you're not looking to pay much, otherwise wouldn't have looked to a forum for free advice :) unfortunately, an entire site isn't usually produced out of one thread, especially not one that looks to contain as much functionality as the one you're looking to build. i'll get you started here though.

1) Clock timer to countdown current pick

var pickTime = "12:55";
function timerUpdate(){
var timeparts = (new Date(0)).split(":");
var hDiff = parseInt(pickTime.split(":")[0])-parseInt(timeparts[0]);
var mDiff = parseInt(pickTime.split(":")[1])-parseInt(timeparts[1]);
document.getElementById("objectToContainTimeRemainingsId").innerHTML = hDiff + " hours and " + mDiff + " minutes remaining";
}
setInterval("timerUpdate()", 1000);


2) Not quite certain what that means having never seen a nascar race in my life
3) Display of drivers avaliable...

//This function does not use an asynchronous call, you can have someone rework it if you're dead set on the async part, this is to limit the number of open connections though
function updateList(){
var xhrObject = getXhrObject();
xhrObject.open("get", "availabledrivers.php", false);
xhrObject.send("");
var listObj = document.getElementById("driverList");
while(listObj.firstChild)
listObj.removeChild(firstChild);
listObj.innerHTML = xhrObject.responseText;
setTimeout("updateList()", 500);
}

you'd need to change the availabledrivers.php to whatever page will be returning the list of available drivers and driverList to the id of the html element containing the list of drivers
4) display of 8 teams...
you'll need to have a database or other read/write source for storing and reading the values you're talking about here, write a page (php, asp, jsp, whatever you want) to return the results from the database about the current race & probably format it as xml but you could do json or csv or some other format, however you want to do it, & follow the above format. also, you say multiple times "as they are picked" ajax isn't an eventing thing, it's just a way for your browser to get updated information from a server. when someone clicks on a link, the only thing notified is the server & the server only returns information on a request, which means that it will not notify the other people when someone picks something, making it necessary to do polling instead (the periodic checking for updated information on the server) & since there is a limit of 2 connections to any given server at any given time in accordance with the HTTP strict protocol asynchronous requests may not work because they can pile up too quickly unless you set the next polling interval on the return of the async handler. long story short, make a page that gets who picked who from a database, format that data as xml, return it, then you'll have to write a function to interpret that data & dispatch the information to the specific areas of your page as necessary, document.getElementById is a method you'll use a lot in this, as well as XMLDOM functions for browsing the responseXML field of your xhr request
5) chat client idea is nice but a lot more work than it is to say, again you'll be relying heavily on your database & ajax polling & a separate page to format the data.

note above i referenced a function called getXhrObject, this is not an actual function in the js language & it isn't defined anywhere in the code i gave you, it's just a general way of saying write a function to return a new instance of the appropriate type of xhr for the browser the page is being viewed on, there are tons and tons of premade scripts for that, just pick one that suits you & change getXhrObject to the name of the function with the same purpose.