hi Bob,
I got the code running, but there seems to be a bit of a problem - the 'Other' field has the popup, which is correct, but when you type inside the Other field the 'NPI#' and 'LIC#' fields are greyed-out and not writeable... it was all the radio buttons that were supposed to turn-off (or be cleared) when the 'Other' field is entered.
Just to be clear, here is the logic:
condition #1:
user selects radio button for either MD or DO, the NPI alert is fired and the NPI# field is required.
condition #2:
user selects any of the other radio buttons, the Lic alert is fired and the LIC# field is now required, the NPI# field is not required.
condition #3:
user clicks the Other text field, the Other alert is fired, all radio buttons are reset to no-selection, neither NPI nor LIC field are required, both fields are writeable.
I know this is all more complicated that you'd probably hoped, but I will gladly pay for your time. And thank you for all your efforts to-date - you're a huge help.
Here is the most recent javascript:
window.addEvent('domready', function() {
// !! important !! replace medical_info with the name of your form
var form, npi, lic, npi_radios, lic_radios, req, other;
npi = $('npi');
lic = $('lic');
other = $('choose_other');
npi_radios = $$('input[name=prof-type-npi]');
lic_radios = $$('input[name=prof-type-lic]');
req = "validate['required']";
npi_radios.each(function(item) {
item.addEvent('click', makeNpiRequired);
});
lic_radios.each(function(item) {
item.addEvent('click', makeLicRequired);
});
other.addEvent('keyup', makeOtherRequired);
other.addEvent('click', function() {
alert('Please type your professional title in the "Other" field.\n\n*If you are either a Medical Doctor or Doctor of Osteopathic medicine, you must enter your NPI# in the space provided.\n\n*If you are a PhD, PharmD RPh, PA, RN or NP, you must enter your State Lic# in the space provided.\n\nClick OK to continue.');
});
function makeOtherRequired() {
if ( !other.value ) {
lic_radios.each(function(item) {
item.disabled = false;
});
npi_radios.each(function(item) {
item.disabled = false;
});
return;
}
lic_radios.each(function(item) {
item.checked = false;
item.disabled = true;
lic.setProperty('class', '');
formCheck_medical_info.dispose(lic);
});
npi_radios.each(function(item) {
item.checked = false;
item.disabled = true;
npi.setProperty('class', '');
formCheck_medical_info.dispose(npi);
});
other.addClass(req);
formCheck_medical_info.register(other);
}
function makeNpiRequired() {
lic_radios.each(function(item) {
item.checked = false;
});
if ( lic.hasClass(req)) {
lic.setProperty('class', '');
formCheck_medical_info.dispose(lic);
}
if ( other.hasClass(req)) {
other.setProperty('class', '');
formCheck_medical_info.dispose(other);
}
if ( npi.hasClass(req)) {
return;
}
npi.addClass(req);
formCheck_medical_info.register(npi);
alert('Based on your selection, to submit this form you must enter your NPI# in the space provided below.\n\nYou may also provide your State Lic#, but it is not required.\n\nClick OK to continue.');
}
function makeLicRequired() {
npi_radios.each(function(item) {
item.checked = false;
});
if ( npi.hasClass(req)) {
npi.setProperty('class', '');
formCheck_medical_info.dispose(npi);
}
if ( other.hasClass(req)) {
other.setProperty('class', '');
formCheck_medical_info.dispose(other);
}
if ( lic.hasClass(req)) {
return;
}
lic.addClass(req);
formCheck_medical_info.register(lic);
alert('Based on your selection, to submit this form you must enter your State Lic# in the space provided below.\n\nClick OK to continue.');
}
});
Here is the most recent HTML:
<form id="medical_info" name="medical_info" action="/medinfo-thank-you" method="get">
<p>
<div style="margin-bottom:5px;"><strong><em>Your personal and professional information:</em></strong></div>
<div style="margin-bottom:5px;"><label for="from"><span style="color:red;">*</span>Full Name: </label><input class="validate['required']" size="80" name="from" id="from" type="text" value="" /></div>
</p>
<p>
<span style="float:left;display:inline;width:auto;color:red;">*</span>
<div name="" id="choose_npi" style="float:left;">
<input type="radio" name="prof-type-npi" id="md" value="MD" /> MD
<input type="radio" name="prof-type-npi" id="do" value="DO" /> DO
</div>
<div name="" id="choose_lic" style="float:left;">
<input type="radio" name="prof-type-lic" id="phd" value="PhD" /> PhD
<input type="radio" name="prof-type-lic" id="pharmd" value="PharmD" /> PharmD
<input type="radio" name="prof-type-lic" id="rph" value="RPh" /> RPh
<input type="radio" name="prof-type-lic" id="pa" value="PA" /> PA
<input type="radio" name="prof-type-lic" id="rn" value="RN" /> RN
<input type="radio" name="prof-type-lic" id="np" value="NP" /> NP
</div>
<div name="" id="choose_other_container" style="float:left;">
<label for="prof-type-other"> Other:</label>
<input type="text" name="prof-type-other" id="choose_other" size="20" value="" />
</div>
<div class="clr"></div>
<div>
<label for="npi">NPI#:</label>
<input class="" size="20" name="prof-type-npi" id="npi" type="text" value="" />
<label for="lic">State Lic#:</label>
<input class="" size="20" name="prof-type-lic" id="lic" type="text" value="" />
</div>
</p>
<input type="submit" value="Submit" />
</form>