Hello,
I'm developing a website for my brother. In it will be an inputform, on which I like to have a number of checks. Using dynamic HTML, I have a system that indicates which fields are incorrect or blank next to the input field: there is a * next to the required input fields; if they are left blank or are incorrect, an errormessage is placed next to it.
On the form is a radio button selector to select the ways of contacting when an order has arrived; choices are: telephone, fax, email, gsm, sms. I have a function that is called for each inputfield (for phone number, mail address, ...) and takes the radiobutton into account:
This above script works perfectly, only that it doesn't check for the mobile number when SMS is selected via the radio button.
Now, in the case of SMS, I would it to do the exact same checks as for mobile. My first thought was to add the following line in 'position 1':
Oddly enough, this cause the check to work for sms, but no longer for gsm... .
It still doesn't work if I rename the occurances of medium prior to 'position 1' to i.e. medium1 and change the above line to:
I know I can add the whole SMS check with sufficiant if's and manually linking it with GSM (and it most likely will work), but I'm hoping to keep the code this compact. I'm stumped as to why my described attempt doesn't work...
Any thoughts? Suggestions?
Thanks!
Jörg
I'm developing a website for my brother. In it will be an inputform, on which I like to have a number of checks. Using dynamic HTML, I have a system that indicates which fields are incorrect or blank next to the input field: there is a * next to the required input fields; if they are left blank or are incorrect, an errormessage is placed next to it.
On the form is a radio button selector to select the ways of contacting when an order has arrived; choices are: telephone, fax, email, gsm, sms. I have a function that is called for each inputfield (for phone number, mail address, ...) and takes the radiobutton into account:
Code:
function CheckContact(medium) { verplicht = document.getElementById('b'+medium).checked; //radio button that indicates medium: btel/bemail/bfax/bgsm/bsms //verplicht == true if the radio button for the medium is checked //verplict = Dutch for requiered s=document.getElementById(medium).value; // input box for the phone number, mailaddres, ... (named to match with medium) // POSITION1 (for my question) // klaarmaken van foutboodschap if (medium=='email') document.getElementById('e_'+medium).innerHTML="E-mail address"; else if (medium=='tel') document.getElementById('e_'+medium).innerHTML="Phone number"; else if (medium=='fax') document.getElementById('e_'+medium).innerHTML="Fax number"; else if (medium=='gsm') document.getElementById('e_'+medium).innerHTML="GSM number"; if (s=='') { // blanco if (verplicht) { document.getElementById('e_'+medium).innerHTML+=" has to be provided"; return false; } else { document.getElementById('e_'+medium).innerHTML=""; return true;} } else { // if blanco if (verplicht) { if ((medium=='email' && (s.indexOf("@")<1)) || ((medium=='tel' || medium=='fax') && (s.length<9)) || (medium=='gsm' && (s.length<10))) { document.getElementById('e_'+medium).innerHTML+=" is incorrect"; return false; } // verplicht + fout else { document.getElementById('e_'+medium).innerHTML="*"; return true; } // verplicht + correct } else { // if verplicht if ((medium=='email' && (s.indexOf("@")<1)) || ((medium=='tel' || medium=='fax') && (s.length<9)) || (medium=='gsm' && (s.length<10))) { document.getElementById('e_'+medium).innerHTML+=" is incorrect (leave blank if none)"; return false; } // foutief else { document.getElementById('e_'+medium).innerHTML=""; return true; } } // else verplicht } // else blanco }
This above script works perfectly, only that it doesn't check for the mobile number when SMS is selected via the radio button.
Now, in the case of SMS, I would it to do the exact same checks as for mobile. My first thought was to add the following line in 'position 1':
Code:
if (medium=='sms') medium='gsm';
It still doesn't work if I rename the occurances of medium prior to 'position 1' to i.e. medium1 and change the above line to:
Code:
if (medium1=='sms') medium='gsm' else medium=medium1;
Any thoughts? Suggestions?
Thanks!
Jörg
Comment