/    Sign up×
Community /Pin to ProfileBookmark

Help with Javascript in GreaseMonkey

i am trying to write this simple script for use in greasemonkey that will not allow me to login to a website with a certain screen name. this is what i have, there seems to be a problem with the ‘if’ part of the script.

function newsubmit(event) {
var target = event ? event.target : this;

if (window.getElementById(‘userid’).inputtext.value = “someid101”) {
alert(‘Can’t login with someid101’);

}

else {

this._submit();

}
}

window.addEventListener(‘submit’, newsubmit, true);

HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
HTMLFormElement.prototype.submit = newsubmit;

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@blue-eye-labsNov 08.2009 — This could (or could not) be the problem: You're using document.getElementById("userid").inputtext.value;

Shouldn't you be accessing the input's value attribute directly?
Copy linkTweet thisAlerts:
@buttmonkeyauthorNov 08.2009 — ok, so i removed the 'inputtext' and changed 'document' to 'window' and just put it in an alert() without the if().

so document.getElementById('userid').value is returning the proper value. but i still can't get it to work in the 'if (document.getElementById('userid').value = "sometext")' event.

i just want it to read the userid box for a certain string and if it contains that string it will not follow through with the submit.


please help
Copy linkTweet thisAlerts:
@blue-eye-labsNov 08.2009 — You're using a setter not a comparison equals.

"=" means make the value on the left equal to the one on the right. "==" means compare the equality of the value on the left with the value on the right.

What you should have is:
[CODE]
if( document.getElementById("user_id").value == "my_value" ) {
//Do something
}
[/CODE]
Copy linkTweet thisAlerts:
@buttmonkeyauthorNov 08.2009 — hey thanks, that worked!

still having one last issue with this script.

it works as follows: when the user id is a certain value it will delete it and make the user aware on the click of the submit button.

but how do i stop the submit button from getting entered after the alert is triggered.




function newsubmit(event) {


if (document.getElementById('userid').value == "test"){

document.getElementById('userid').value = "";
document.getElementById('pass').value = "";
alert('bad user login');



}

}



window.addEventListener('submit', newsubmit, true);



HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;

HTMLFormElement.prototype.submit = newsubmit;


i need the form not to submit after the if = true
Copy linkTweet thisAlerts:
@blue-eye-labsNov 09.2009 — use event.preventDefault(); or returning false normally should prevent any further action.
Copy linkTweet thisAlerts:
@buttmonkeyauthorNov 09.2009 — hey thanks man, it works great now. of all the the javascript heads on the web.. you're the only one that helped me.. appreciate it!!!
Copy linkTweet thisAlerts:
@blue-eye-labsNov 10.2009 — You're welcome, I'm glad it worked.
×

Success!

Help @buttmonkey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...