Question:
Javascript verification?
2013-01-28 02:35:38 UTC
Basically, I have created a form using HTML and in the code is a box to enter a member ID, the Member ID has to be within certain parameters, 1000 to 9999. However I need an alert that tells me when the ID entered is out of them parameters, eg like a Javascript function, however i am unfamilliar with Javascript so explaining everything would be useful. I haven't entered any Javascript in yet because it was frustrating me. This is the code I have used so far, there is more above eg html open tag etc, just limited by characters,

If you're interested in any of the trips featured above, then please fill out the form below to register your interest! Hurry though, only limited spaces, first come first
served!



Forename:




Surname:




Email Address:




Member ID:


(1000 to 9999)

Trip:









Three answers:
2013-01-28 03:42:16 UTC
I don't think using spaces in name parameter is a good idea. Better use name="EmailAddress" and name="MemberID"

Also using mailto in form action is not the best solution. It assumes use user has some email software installed and configured (like outlook) and you can't do proper redirects after form submission succeeds of fails.



First give the member id textbox an id parameter id="MemberID"

Javascript:



function ValidateMemberID(){

var mID = document.getElementById('MemberID').value;

var min = document.getElementById('MemberID').getAttribute('min');

var max = document.getElementById('MemberID').getAttribute('max');



if(parseInt(mID)max){

alert('Incorrect member id');

return false;

}

document.getElementById('myForm').submit();

}



Assign this function to submit button's onclick event



and that's it.



EDIT:

Since yahoo messes up the code here is a working example (just click 'Run')

http://tinkerbin.com/6QFIgepz

I gave the form id, submit is now type="button" and the submit is called in javascript, since submit buttons sometimes seem to ignore JS return value
?
2016-10-13 05:23:14 UTC
i did no longer understood your code thoroughly! yet this line of code is incorrect if(solutions > "") Now tell me do you think of logically its astonishing ??? If i ask you that solutions variable has some value than could that is extra desirable than empty string (""). you ought to use == to evaluate strings on your code. so the line must be if(solutions == "") or could be its an array than you may verify its length if(solutions.length > 0) Cheers!!!
AnalProgrammer
2013-01-28 03:49:35 UTC
Try this link.



Have fun.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...