-2

I am using Tampermonkey on chrome and running it on a website. I am trying to log in using login credentials. I got it to click log out, not log in. Here's my whole code:

// ==UserScript==
// @name           Blah
// @namespace      Blah.com
// @description   .
// @include        http://Blah.com/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==

//function logOut()

//{
    // Log out of Blah 
//  Blah = document.getElementsByName(“Blah");
//  for i in 1..2 do
//  log in
//  //username = Username1
//  password = Password1
//  {
//      {
        //  greyButtons.click();
//      }
//  }
//}

function logOut()
{
    // Log out of Blah incase already signed in
    document.getElementById('Blah').click();
}

logOut();

function logIn()
{
    document.getElementById("Header_Login_tbUsername")
    //I don't know what to put here
}

logIn();
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
jackpot
  • 23
  • 5
  • See, also, http://stackoverflow.com/questions/16029674/how-to-set-two-inputs-and-ungrey-a-button for AJAX driven pages (works on static pages too). – Brock Adams Oct 27 '14 at 05:03

1 Answers1

0
document.getElementById('username').value = 'MyLogin';
document.getElementById('password').value = password; // I don't care how you get it
document.getElementById('loginbutton').click();

Also, why require jQuery if you're going to go all pure JS?

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • 1
    jQuery because: (1) He's probably also doing other stuff, (2) this answer will only work on the simplest of static pages, (3) he may have grabbed a template and the smartest ones use jQuery as a base. – Brock Adams Oct 27 '14 at 04:49
  • @BrockAdams: Fair enough, but in that case why not `$('username').val('MyLogin')`? I'm not against jQuery, but for consistency. – Amadan Oct 27 '14 at 04:51
  • That may work (simple static page), but the OP hasn't provided needed detail. I haven't upvoted this answer yet because this question is almost a duplicate and probably should be closed, irregardless. – Brock Adams Oct 27 '14 at 04:54
  • @BrockAdams: Probably, yes. Agreed. – Amadan Oct 27 '14 at 04:56
  • So what do i change the code to and where? – jackpot Oct 27 '14 at 12:50
  • SO pi did that, and its not putting in the words. It seems it can't find the boxes. ** function logIn() { document.getElementById('Header_Login_tbUsername').value = 'MyLogin'; document.getElementById('Header_Login_tbPassword').value = 'test'; // I don't care how you get it document.getElementById('loginbutton').click(); } logIn();** – jackpot Oct 27 '14 at 13:02
  • 1
    Are the IDs correct? Is the timing correct (i.e. do the input boxes exist at the time you call `login()`)? – Amadan Oct 28 '14 at 01:03