Click to See Complete Forum and Search --> : Odd Question...
DanUK
04-16-2003, 05:49 PM
Good evening guys. I don't know if this is possible, if it's not is there anything else you can recommend?
I have a site with several 'application' forms. I've already filtered some abuse by making fields required and checking email addresses are formed correctly, and it only contains valid characters etc.
I've seen elsewhere 'Human Input' where a random image is shown containing a word, which must be inputted into a field. Is there a way I can achive this? My host doesn't support PHP... or is theer any other ideas to try and stop false applications?
Lastly, I have a password form... which looks something like:
else if (form.userPASS.value =="") {
alert("Please include your desired username password.");
form.userPASS.select(); }
Is there way to having 'minimum' characters? I've already got maxlength etc...
Thanks for any infos you can give me.
:rolleyes:
DanUK
04-16-2003, 05:55 PM
I was just thinking, this could be anything, not even an image, perhaps a 'number' that comes up somewhere or something :\ hehe
DrDaMour
04-16-2003, 06:29 PM
since you aren't using php or any othe rserver side code, what i would do for hte human test is generate a random number
var x = Math.round((Math.random() * 100) + 1));
then print it out using document.write or innerHTML or something, then when teh form is submitted check the users input against the variable x. It's a cheap way to do it, but if your code really is only on client side, then this shoudl be enough for you
DrDaMour
04-16-2003, 06:52 PM
yeah but my thought was that if this form is really going to be server side, then there definately isn't a big likelyhood that it's so useful that someone would bother to write that program. But of course why woudl you need the verify anyways...what came first the chicken or the egg?
DanUK
04-17-2003, 04:10 PM
hi again.
how should this one ( var x = Math.round((Math.random() * 100) + 1)); ) be coded? Idont really understand...sorry and thanks for any hlep.
DrDaMour
04-17-2003, 04:27 PM
x is now a randomly generate number, so you have to output it to the screen whereve you want.....document.write(x) would be one solution.
DanUK
04-17-2003, 04:44 PM
i'll try ... thanks *clueless look*
DrDaMour
04-17-2003, 04:51 PM
i'm sorry dude, stop doing that clueless thing, it makes noone happy and start learning this (http://developer.netscape.com/docs/manuals/js/client/jsref/index.html) then we can all be happy. What you're asking to do takes some decent conceptual grasp of JS.
DanUK
04-17-2003, 05:42 PM
I'm sorry if i annoyed anyone, that wasn't my intention. Can i please show something that i wrote earlier:
Thanks for the help. Here's my £0.02 worth ... I know it must be frustrating for you guys having to answer all types of queries etc, and to you, I understand, it must seem like we just take what you say and don't try at all. Some people like me, really don't find things like this easy. I personally spent a lot of time learning HTML, or trying to, javascript I could never really understand or try to get working. That's why people liek you, and places like this are brililiant. It might not show that people are actually thankful for your help, but personally I am. anyway thanks again __________________ Kind regards, Daniel.
Once again...sorry if I annoyed you in any way.
DanUK
04-18-2003, 06:33 PM
I still can't get this going.
I've tried putting
<script>
var x = Math.round((Math.random() * 100) + 1));
</script> in the HEAD.
and in BODY a print...
DanUK
04-18-2003, 07:06 PM
ok that works, the original one i put did but not in the right place, but how can i make it check the number specified matches what the user enters into a box before allow to submit? Or is there's osmething i can read to show me?
thanks
DanUK
04-18-2003, 07:45 PM
thanks so much dave !!!
if i was going to incorporate this into my following code, would i do it like this? The field is named 'hin'
var nbr = Number(document.fm.hin.value);
if (nbr != rnd) {
errors += "You must enter the number shown.;\r";
fm.hin.select();
}
script :
function simpleCheck(fm) {
var errors = "";
if (!/^[a-z0-9]+$/i.test(fm.newuser.value)) {
errors += "Please include your desired use;\r";
fm.newuser.select();
}
if (fm.userPASS.value =="") {
errors += "Please include your desired user password;\r";
fm.userPASS.select();
}
if (fm.userRPTPASS.value =="") {
errors += "Please repeat your desired user password;\r";
fm.userRPTPASS.select();
}
if (fm.userPASS.value != fm.userRPTPASS.value) {
errors += "Your passwords did not match, please try again;\r";
fm.userPASS.select();
}
if (!/^\w+@\w+\.[a-z]{2,3}(\.[a-z]{2})?$/i.test(fm.userEMAIL.value)) {
errors += "Please include your e-mail address. Should be in 'you@host.com' format;\r";
fm.userEMAIL.select();
}
if (fm.policyON.checked==false) {
errors += "You forgot to tick the box stating you agree to our terms;\r";
fm.policyON.select();
}
if (errors != "") {
errors = errors.substr(0,errors.length-2);
alert("The following fields were misformed, please retry:\r" + errors + ".");
return false;
}
return true;
}
DanUK
04-18-2003, 09:13 PM
thanks alot dave. works PERFECT!
DanUK
04-19-2003, 07:01 AM
Hi again.
Using the code I pasted above (the Javascript for form validation) is there anything there that could cause 'odd' look with Konqueror/Mozilla browser? It is fine in my Internet Explorer but under Konqueror/Mozilla it looks really long, as if a 'new line' hasn't begun, it just carries on and looks wrong.
Any info you can give will be gratefully appreciated. Many thanks.
DanUK
04-19-2003, 07:29 AM
brilliant thanks !
DanUK
04-20-2003, 10:55 AM
hi again.
If i wanted the number generation to be within 1000, do i just change
rnd = Math.round((Math.random() * 100) + 1);
to
rnd = Math.round((Math.random() * 1000) + 1);
and that would give a random number between 0 and 1000?
Thanks !
DrDaMour
04-20-2003, 11:47 AM
it never hurts to try something out before you get verfication of it's correctlness in javascript. It's not like it's the A-Bomb