I did a search and could not find the answer I needed, forgive me if this is has already been answered.
I very new to JavaScript and I need to validate a text field after a checkbox has been clicked. This is part of a larger form validation. I am looking for the simplest and easy solution to this issue. I have seen a couple of other examples that are far too complicated for the my needs.
The form is asking a user to identify a referral source. If the referral source is a website, it wants the user to provide a URL. To clarify, all it needs to do is verify that if the website checkbox is clicked then there is text in the corresponding textbox.
Here's what i'am been trying to make work (Thanks in advance for any help)
Code:function CheckAbout() { var chks = newArray('info_newspaper', 'info_magazine', 'info_billboard', 'info_website', 'info_other'); var checkSelected = false; for (i=0; i < chks.length; i++){ if (document.getElementById(chks[i]) && document.getElementById(chks[i]).checked) { checkSelected = true; break; } } if (!checkSelected){ Message = "Please tell us tell us how you heard about us" + "\n" } if (document.getElementById(chks[1]) && document.getElementById('info_website_url')) { if (document.getElementById(chks[1]).checked && (document.getElementById('info_website_url').value == '')){ Message = "Please enter some text in txtBox 2." + "\n" document.getElementById('info_website_url').focus(); } } if (document.getElementById(chks[2]) && document.getElementById('info_other_txt')) { if (document.getElementById(chks[2]).checked && (document.getElementById('info_other_txt').value == '')){ Message = "Please enter some text in txtBox 3." + "\n" document.getElementById('info_other_txt').focus(); } } else { Message = "" } return Message }


Reply With Quote

Bookmarks