Forum Moderators: open

Message Too Old, No Replies

form dom and reg expr

         

quartzy

3:07 pm on Apr 13, 2009 (gmt 0)

10+ Year Member



I have this script, which is causing an error from firebug, saying that return is not in the function, I have no idea why it is saying this, as I have return in the function. It is the line that says if valid return = true. Can anyone help? It is quite a complicated form that has taken me days to figure out.

<script type="text/javascript">
/* <![CDATA[ */

function validPostCode (){
return /^([A-Z]{2}[0-9]{1,2}\s[0-9]{1,2}[A-Z]{1,2}$)/i.test(validpostcode);
}
function validSpecialPostCode (){
return /^(([M][K][1-15]{1,2})¦([M][K][1][7])¦([M][K][1][9])¦([M][K][7]{2})\s[0-9]{1,2}[A-Z]{1,2}$)/i.test(validspecialpostcode);
}
function validFcard () {
return /^(\W{13}\d[!&\?@]{1}$)/i.test(validfcard);
}

function get(id) {
return document.getElementById(id); }
var message = 'Please correct invalid input:<br />';
var messageNode = get('intro');
var valid = true;
var postcode = get('postcode').value;
var specialpostcode = get('postcode').value;
var fcard = get('fidelity card').value;

if (!validPostCode()){
valid=false;
message.push('Postcode is not valid');

}
if (!validSpecialPostCode()){
valid = false;
message.push('Postcode is not valid');
}
else if (validSpecialPostCode ()){
valid = true;
alert ("You will received a special gift on submission");
}

if (!validFcard ()){
valid=false;
message.push('Card is not valid');
}
if (valid) {
return true;
}
else {

while(messageNode.childNodes.length>0) messageNode.removeChild(messageNode.childNodes[0]);
for(var i=0; i < message.length; i++) {
messageNode.appendChild(document.createTextNode(message[i]) );
messageNode.appendChild(document.createElement('br') );
messageNode.removeChild(messageNode.lastChild);
}
}
// end of verify
window.onload = function() {
if (window.addEventListener) {
document.getElementById('submit').addEventListener('click', verify, false );
}
}
/* ]]> */
</script>

Fotiman

3:15 pm on Apr 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Which function do you think that return is a part of? Firebug is correct, it is not included in any function. The function above that is the 'get' function, which contains only one statement and then closes.

quartzy

3:25 pm on Apr 13, 2009 (gmt 0)

10+ Year Member



I found it, missed out
function verify(evt) {
thanks for your help, no errors now