Question

I am trying to create a downloads page, where the user is to select the item they wish from the dropdown list, in doing this the page should spawn in text in the text area based on what they selected, which is a small HTML formatted description of the file they selected. Then i wish to have a "Download!" button, which when clicked will check the value in the dropdown and then take the user to thier download which is hosted at mega. I have the basic idea for how to make the text spawning work, however for some reason my if statements seem as good as useless; i can't get it to spawn ANY text into the text area, and i can't figure out how to link this to the button. I apologise in advance that this is quite vague and LQ code (I prefer PHP/python to JS).

This is what i have so far:

            <!DOCTYPE html>
            <html>
            <head>
            <script type='text/javascript'>
            var file;
            function ChooseDownload()
            {
              if(document.getElementById("item").value == "Shell"){
                document.getElementById("what").value="You selected Shell";
                file = "http://mega.co.nz/[file]";
              }
              else if(document.getElementById("item").value == "Bot"){
                document.getElementById("what").value="You selected Sources";
                file = "http://mega.co.nz/[file2]";
              }
            }

            </script>
            </head>
            <body>
            <h5><p>Please Select File to download:</p></h5>
            <p>
            <form>
            <select name="item" onchange="ChooseDownload()">
            <option value="Blank">Select Download</option>
            <option value="Shell">My PHP Shells</option>
            <option value="Bot">Botnet Sources</option>
            <option value="Skype">Skype 6.9 Win</option>
            <option value="Xchat">Xchat Free</option>
            <option value="Cod5">Custom Maps</option>
            </select>
            </form>


            <p><form method="get" action="url">
            <button type="submit">Download!</button>
            </form> </p>


            </p>
            <p>&nbsp;</p>
            <p><br>Contents:<br><textarea name='what' rows='15' cols='60'></textarea><br/></p>
            </body>

            </html>

Thanks for any ideas/Help.

Était-ce utile?

La solution

Your problem is that you need to pass some kind of parameter to the ChooseDownload function, based on that you can make decisions.

try this:

function ChooseDownload(selected)
    {
        switch(selected.value){
            case "Shell":
                    //some action
                   break;
            case "Bot":
                //some action
                break;
            case "Skype":
                //some action
                break;
            case "Xchat":
                //some action
                break;
            case "Cod5":
                //some action
            break;
            default:
                //unknown option
                break;
        }
    }

and your HTML to this:

<select id="item" onchange="ChooseDownload(this)">
    <option value="Blank">Select Download</option>
    <option value="Shell">My PHP Shells</option>
    <option value="Bot">Botnet Sources</option>
    <option value="Skype">Skype 6.9 Win</option>
    <option value="Xchat">Xchat Free</option>
    <option value="Cod5">Custom Maps</option>
</select>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top