Need help fixing javascript..

Discussion in 'JavaScript' started by VsUK, Mar 19, 2010.

  1. #1
    For the record, im a noob at javascript & if there was a lvl below noob id use it to :D

    Anyways, my code blow is supposed to automate on a website i use a quantity & submit with just one click using javascript. The help i got wasn't successful as it dosnt act as a URL or interact with the webpage & i need it to be used as a URL.

    My Goal is to make a simple php page which i already have & a list of links. Now the links will be made up of javascript as soon as i get a working example i can edit. When i click the links, on the webpage it automatically sets quantity & hits the Sell submit button for me, however it dosnt work & im desperate to get it fixed. On the webpage is a slider that sets the quantity, i can manually set quantity as we have to use a slider we click & drag left or right then we click Sell & it sells the type of drugs which is part of the game we wanted. I grabbed the POST info using Live Headers firefox plugin. I hope someone can fix this for me.

    Live Headers info:
    POST /fiends.php drugtype=lsd&sqty=5201
    Code (markup):
    Javascript Code:
    1."href="javascript:
    2.var doc = document;
    3.var aForm = doc.createElement("form");
    4.doc.getElementsByTagName("body")[0].appendChild(aForm);
    5.aForm.setAttribute("action", "http://www.greedinc.com/fiends.php?drugtype=lsd&sqty=5201");
    6.aForm.setAttribute("method", "POST");
    7. 
    8.var aInput = doc.createElement("input");
    9.aForm.appendChild(aInput);
    10.aInput.setAttribute("type", "hidden");
    11.aInput.setAttribute("name", "drugtype");
    12.aInput.value = "lsd";
    13. 
    14.aInput2 = doc.createElement("input");
    15.aForm.appendChild(aInput2);
    16.aInput2.setAttribute("type", "hidden");
    17.aInput2.setAttribute("name", "sqty");
    18.aInput2.value = '5201';
    19.aForm.submit();">
    Code (markup):
     
    VsUK, Mar 19, 2010 IP
  2. VsUK

    VsUK Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    anyone? pls :(
     
    VsUK, Mar 20, 2010 IP
  3. mattinblack

    mattinblack Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why on earth do you need to create the form in javascript? And why put the whole function inside a link?
    Just write one form in html, make all the fields hidden and add no submit button. Then add one javascript function
    and call this from each link.

    <form name=plastic method=post target=whatever.php>
    <input type=hidden name=sqty>
    <input type=hidden name=drugtype>
    </form>
    <script>
    function dosubmit(drug,qty){
    plastic.sqty.value=qty;
    plastic.drugtype=drug;
    plastic.submit()
    }
    </script>

    <a href="javascript:dosubmit('halo-peridol',6000);">link1</a><br>
    <a href="javascript:dosubmit('lsd',2100);">link2</a><br>
    <a href="javascript:dosubmit('w-w-w-for white',6);">link3</a><br>

    Much easier
     
    mattinblack, Mar 20, 2010 IP
  4. VsUK

    VsUK Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    They dont name there forms ive found out & ive been told that wouldnt work :( this is difficult..

    However the forms are unnamed, each form will only work with a drugtype for example lsd so would it be able to find the form to send to?
     
    Last edited: Mar 20, 2010
    VsUK, Mar 20, 2010 IP