hello, I am fairly new to javascript and this is really the first dynamic site I am attempting. I am good with perl and thats it. I have noticed with javascript examples they return true or false........ what exactly does the value "true" or "false" get returned to? is it assigned a variable name?
I am wondering a simple way to check if a var is a certain amount of digits like 10 for phone number and 5 for zip code.
please see the registration page here iboost.biz
when you submit the form it calls a function which returns the eroors in a popup box as you will see. The phone number is set as var p_num without calling another function what is a simple if statement to see if p_num is 10 digits. I already have it only accepting numbers.
if (p_num ???????????){
my_errors = my_errors + "Phone Number Must Contain 10 Digits";
}
thanks guys!
When something is returned if it's not assigned or done something with its return value is gone forever.
Code:<scriopt>
function find() {
return "134";
}
document.write(find());
if(find()=="134") {
document.write("Yes!");
}
var findvar = find();
Thank you that was a very simple and very useful explanation it makes a lot of sense. Any help with my question about containing a certain amount of digits or characters?
Yes
Code:<script>
var mystring1 = "hello world";
document.write(mystring1.length);
</script>
im sorry man i dont quite understand that.....
say i have....
<script>
function register(){
var p_num = document.register.phone.value;
if (p_num ????????){
var error = "invalid phone number";
}
}
</script>
i need it to return var error with invalid phone number if it does not contain exactly 10 digits. I have googled it but get complicated and not straight forward answers. I just need something simple thanks
Code:<script>
function register() {
if(document.register.phone.value.length != 10) {
document.write("Invalid phone number.");
return false;
}
return true;
}
</script>
thanks a lot man
lol sorry can you please explain what the hell return true and false does! I dont get it what is the point of returning true and false and how do u tell if it was returned true or fals lol sorry might sound like a dumb question but it would reallly explain a lot! thanks
Depending on how your using you this you may not need it. If this was in the "submit" button and it returned false in it's "onclick" I believe it will not allow you to submit the form which is what you want.
True/false is boolean values. If you returned "register()" you could test if it's true or false"
Code:<script>
function register() {
if(document.register.phone.value.length != 10) {
document.write("Invalid phone number.");
return false;
}
return true;
}
if(register()) {
document.getElementById('errors').innerHTML = "Correct value!";
}
</script>
gotcha thanks again man
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks