SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jun 17, 2002, 14:42 #1
Javascript check based on two elements...
What is wrong with this code? I'm relatively new to Javascript, therefore, not very good at spotting why it does not work at times. Very grateful for any help.
I have a checkbox that, when checked, has a value of "Yes". If checked and form field "_013_currsite" is blank I want a prompt box to appear asking for "...current web site". I then want to assign the value of the prompt field to "_013_currsite".
In the checkbox input I have an onBlur event calling wwwPrompt.
At the moment, the onBlur calls the function. The value entered in the prompt assigns to "_013_currsite"; however, what the function does not seem to spot is when there is an entry in "_013_currsite" already (in which case I do not want the prompt to appear).
Any idea what's occuring here?
PHP Code:function wwwPrompt(enquiryForm) {
if (enquiryForm._016_review_site.value=="Yes" && enquiryForm._013_currsite.value=="");
var www = prompt("Please enter your current web site address.",""); {
enquiryForm._013_currsite.value=www; return false;
}
enquiryForm._017_site_hosting.focus(); return true;
}
-
Jun 17, 2002, 15:04 #2
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is always true:
enquiryForm._016_review_site.value=="Yes"
This can be true or false:
enquiryForm._016_review_site.checked
-
Jun 17, 2002, 15:16 #3
Thanks jofa, however, I changed the script to:
PHP Code:function wwwPrompt(enquiryForm) {
if (enquiryForm._016_review_site.checked && enquiryForm._013_currsite.value=="");
var www = prompt("Please enter your current web site address.",""); {
enquiryForm._013_currsite.value=www; return false;
}
enquiryForm._017_site_hosting.focus(); return true;
}
Not sure where to go from here. Any further thoughts?
-
Jun 17, 2002, 15:40 #4
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Remove the semicolon after if(...)
Code:function wwwPrompt(enquiryForm) { if(enquiryForm._016_review_site.checked && enquiryForm._013_currsite.value=="") { var www = prompt("Please enter your current web site address.",""); enquiryForm._013_currsite.value=www; return false; } enquiryForm._017_site_hosting.focus(); return true; }
-
Jun 17, 2002, 16:00 #5
Excellent, thank you.
Bookmarks