Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   Dropdown bozes and calculating? (https://novahq.net/forum/showthread.php?t=45560)

katana*GFR* 12-05-2010 09:54 AM

Dropdown bozes and calculating?
 
Heya,

i need a kickass direction to something i want to create ^^

I need 3 dropdown menu's next to eachother in which people can select an item and its bonus names..

Small explanation, in that game ( gladiatus ) we have items with an prefix and suffix, they are used to give a basic items its extra stats.

What i want to do is to make it available online ( only working "script" i got is excel )


How should it look? :

3 dropdowns:


|Prefix| ---- |Item| ---- |Suffix|

List of stats
-stat 1
-stat 2
-stat 3
-stat 4
-stat 5
-stat 6


When clicking on it you will be presented with a list of names and when you make your selection it will calculate the stats and show them to you underneath it.

I got no idea on how to start off, so i need some general directions, or even better an example :)

Since the different prefixes and suffixes make up different statistics it needs to calculate the items to given formula..


I hope i made it a bit clear on what i ment ^^

Site im planning to put it on is just a html / css site, nothing fancy there.





*edit, yes i messed up the title, ment Boxes ^^

Scott 12-05-2010 11:06 AM

Whats the formula? Some real live examples of the data and the end result would help alot. I'm sure this can be done with JavaScript..

katana*GFR* 12-05-2010 11:43 AM

1 Attachment(s)
I got an excel sheet which has the stuff in it, bu tmost formulas i got are in german ( which is most likely not your strongest foreign language ^^ )


i'll try to extract the formula again ^^ Been a while since we inserted it :)

katana*GFR* 12-05-2010 11:49 AM

*(&%$^#$_(*$() Copy paste fails, it removes almost all txt.

so a image:
http://i55.tinypic.com/w1z421.png

Scott 12-05-2010 06:45 PM

It would take me a long time to decipher that info :(

katana*GFR* 12-06-2010 02:06 AM

Could you point me to some javascript info with these sorts of info Scott?
As im pretty beat up on what to look for exactly, google isn't as good as it used to be in the old days.. And looking through a miliion pages and trying to weed out the advert links sucks

Scott 12-06-2010 08:22 AM

Yeah searching for quality info now days usually ends up in blog spam.

It looks like drop down's with multi dimensional arrays would work. After the data is gathered from each drop box, the formula needs to be applied to all the drop down's values.

atholon 12-06-2010 09:16 AM

I think I know what you're talking about. Simple javascript should do the trick. I'll try and write something basic you can use.

atholon 12-06-2010 09:39 AM

You could do something like this in javascript:

Code:

function DropDown(targetName)
{
        var dropDownInst = this;
        this.target = document.getElementById(targetName);       
       
        if(targetname == null || this.target == null)
                return;
        // better to add some sort of exception handling here
       
        // Create prefix array
        this.prefixes = ["prefix1", "prefix2", "prefix3"];       
       
        // Create DOM select object
        var prefixSelect = document.createElement("select");       
        this.addOptions(prefixSelect, prefixes);
       
        // This is where we handle adding the item
        prefixSelect.onchange = function(e){ dropDownInst.addItem(this); };
}
DropDown.prototype.addOptions = function(iSelect, iArray)
{
        for(var i=0; i<iArray.length; i++)
        {
                var option = document.createElement("option");
                option.value = iArray[i];
                option.text = iArray[i];
                iSelect.options.add(option);
        }       
}
DropDown.prototype.addItem(iSelect)
{
        var selectedValue = iSelect.options[iSelect.selectedIndex];
       
        switch(selectedValue)
        {
                case "desiredPrefix1":
                        // Add code here to create a new select and append it to the target
                        break;
                case "desiredPrefix2":
                        // Add code here to create a new select and append it to the target
                        break;
                case "desiredPrefix3":
                        // Add code here to create a new select and append it to the target
                        break;
                default:
                        alert("An invalid selection occurred!");
        }
}


katana*GFR* 12-06-2010 11:48 AM

bah, sounds like time to start a java course.. ^^
To bad i knew it wasn't going to be easy ^^

Cheers for the code so far Atholon.
1 thing, this piece only uses the given item + a prefix right?


An would it be possible to read the Prefixes, Items and Suffixes from an .txt file or ini?
Since that is the easy part to create, then the script stay's clean withotu cluttering it with all data..

If i count all prefixes, items and suffixes im nearing ( rough estimate ) 350 lines.. ( each item on 1 line with its + and - effects.. ^^

atholon 12-06-2010 04:06 PM

Yeah the code I attached is not for the full thing, just an example. It basically is set to add a second dropdown box based on the selected values from the first dropdown.

If you want to load it from a text file you'd need a server-side language like PHP or ASP.net and use ajax calls. Javascript can't directly interface with files.

You could use a java applet, silverlight or flash to do the drop downs and read from a text file as well. Think it's easier with JS though.

atholon 12-06-2010 04:16 PM

It might be easier to use ajax actually, because you could load the first drop-down with the default values. Then you'd make an ajax call to your code behind language, it would then filter the results for you, then you can pass it back through an ajax response as an array. You create another drop down and load it with the results stored in the array. Then you do the same thing for a third box.

It just gets sort of messy when you are dealing with several cascading dropdowns, you might be able to find something easier by using that search term "cascading dropdowns".

What programming languages do you use Katana? jQuery (a javascript library) makes it really easy to do ajax stuff.

katana*GFR* 12-06-2010 04:39 PM

Well atm only html ^^ I have been working on so many things that i never could catch up with anything more.. In all those years ^^

Might aswell make sure my excel file is updated with all details first and then try to start teaching myself some tricks.
Been checking out some java builders, but thats a small step to high for me, so let alone that i start Ajax..

I did save all this info tho ^^.

Any help is appreciated, and im willing to learn ^^

I still got my trustworthy DreamWeaver on my PC and that helps me out alot.. Im very visually minded, for html i do know my way by now, but that has taken me some time ^^





PS, msn is jigler@gladiatus.nl
And i can be catched on IRC also alot.. irc.onlinegamesnet.net/6660 Channel: #jigler

Just shout and i'll react asap ^^ on irc i got an bnc, and never change my name to reflect offline / online, so drop a query if you want to know for sure ^^

atholon 12-06-2010 05:41 PM

I guess I should have asked this question: Does your web host support PHP or Asp.net or is it something else? I've done Ajax stuff with both PHP and Asp.net and could probably write you something in a week or two. I am at the end of the semester in school so I've got finals next week and will have little time until they're over.

If you've got the stuff in excel that is great, you'd just have to save a .csv file and you could read the stuff in very easily.

katana*GFR* 12-07-2010 05:33 AM

it supports that offcourse :P

Another thing Atho, where should i focus on as next step after html? I do have to start learning this stuff myself.. But im a bit "lost in the woods" And google has gone downhill the last few years, like Scott mentioned ^^

Any help is always welcome, but i don't want to make it so that you gys do the work and i just sit back and watch.. That is something i hate ^^

atholon 12-07-2010 07:53 AM

I would focus on learning how to read a text file from PHP and using delimeters to break the text into usable data first.

katana*GFR* 12-07-2010 11:43 AM

o0 my post disappeared in the big mists of internet, or i just missed the submit button.. ^^

So i have dug myself a old copy of Lynda.com PHP Essential Training up..

Hello "Hello World" again ^^

Any further recommendations are welcome ^^

atholon 12-07-2010 05:54 PM

I'd look here for learning how to read a PHP file.

I'd look here for learning how to split the lines into the data arrays you want.

Once you've read those pages you should be able to open the file, read it line by line, break each line into an array with the implode method and have the data accessible from the codebehind.

Create an array of arrays as you read stuff in. Once you get to that point I'll help you with the javascript/ajax stuff

Pseudo code:
while there is a line
{
read line, use implode to break the line into an array
put array into another array
}

return the array

atholon 12-08-2010 06:48 PM

Bam, atholon fail, you'd use the function explode();

Here you go:
Code:

<?php

$file = fopen("yourfile.csv", "r") or exit("Unable to open file!");

// Row array
$rows = array();

while(!feof($file))
{
  $columnString = fgets($file);
  $columns = explode(",", $columnString);

  // Add the array of column items to the row
  $rows[] = $columns; 
}
// This would return ALL the data to the javascript with AJAX
echo(json_encode($rows));
?>

You could get away with making multiple AJAX requests and having the code behind filter it but I suggest just doing one AJAX request at the time the page loads. That way you don't have the annoying delay while the results are passed back.

Scott 12-08-2010 07:52 PM

Katana.. Do you have the password to un-protect the cells? The biggest hurdle here is the language, and not being able to pry into the excel formula.

It's more complicated than just building an array. If you look at how cell E are calculated on the first tab, you will see that not everything prefix+item+suffix but there are also conditional statements...


All times are GMT -5. The time now is 06:50 AM.

Powered by vBulletin®