[wtb] Java script modification

Discussion in 'Programming' started by midnight_focus, Jan 26, 2009.

  1. #1
    javascript:function insert(arr,val){for(var i=0;i<arr.length;i++){if(arr[i]==val) return i;}return arr.push(val)-1;}var arr=document.getElementsByTagName("input");var questions=new Array();var answers=new Array();for(var i=0;i<arr.length;i++){if(arr[i].type=="radio"){var j = insert(questions,arr[i].name);if(answers[j]==undefined)	answers[j]=eval(arr[i].value);else{answers[j]=Math.min(eval(answers[j]),eval(arr[i].value));}}}for(var i=0;i<questions.length;i++){var arr2 = document.getElementsByName(questions[i]);	for(var j=0;j<arr2.length;j++)	{if(eval(arr2[j].value)==answers[i])arr2[j].click();}}
    
    Code (markup):
    the code above when written in the address bar should give the correct answer in a multiple choice question (online iq test)or (here )but instead it always pick the first choice.
    How to fix this?
    I need an answer fast please
     
    midnight_focus, Jan 26, 2009 IP
  2. manjifera

    manjifera Well-Known Member

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    118
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    what you want to achive? random? selection?
     
    manjifera, Jan 26, 2009 IP
  3. midnight_focus

    midnight_focus Active Member

    Messages:
    310
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    for example when viewing this site and writing the code in the address bar it should select the correct answer for the questions.

    If you tried my code it will select the first choice for all questions (not the correct one) i need to modify it to select the correct one
     
    midnight_focus, Jan 26, 2009 IP
  4. manjifera

    manjifera Well-Known Member

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    118
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    its not possible untill n unless you know the answers. you have to define them in script! else script will work like mad! :p Select 1st / as per script designed!
     
    manjifera, Jan 26, 2009 IP
  5. midnight_focus

    midnight_focus Active Member

    Messages:
    310
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    I believe it is possible as this code was working with some site and provide the correct answer
     
    midnight_focus, Jan 26, 2009 IP
  6. chmdznr

    chmdznr Active Member

    Messages:
    417
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    Where do you see that this script is working?
     
    chmdznr, Jan 26, 2009 IP
  7. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    IT works for me you just need to specify the last field . which is " by indicating your gender."and then have the form submit it self.
     
    atlantaazfinest, Jan 26, 2009 IP
  8. midnight_focus

    midnight_focus Active Member

    Messages:
    310
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    could you explain more please? what last field and how to change it?
     
    midnight_focus, Jan 27, 2009 IP
  9. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    Well when you input the javascript function into the browser on the page and run it , it will select the answers for you on the form the only answer it doesn't select for you is the last question on the page which is your gender... so just make the function select an answer and submit the form you should be good from there
     
    atlantaazfinest, Jan 27, 2009 IP