jQuery error: ReferenceError: completedInputs is not defined -


i writing jquery check see if input , select elements in div have value set (not null), once have value show next button slide in next part of form.

here markup:

<div id="signupforminner">     <form action="/" method="post" id="form1">         <div id="slide1">                    <label for="title">title:</label>             <select name="title" id="title">                 <option value="">-- please select --</option>                 <?php foreach($this->titles $title) { ?>                     <option value="<?php echo $title; ?>"><?php echo $title; ?></option>                  <?php } ?>             </select>             <label for="firstname">first name:</label><input type="text" name="firstname" id="firstname" />             <label for="lastname">last name:</label><input type="text" name="lastname" id="lastname" />             <label for="email">email address:</label><input type="email" name="email" id="email" /><label for="email">confirm email address:</label><input type="email" id="email_confirm" />          </div>         <div id="slide2">             content in here          </div>         <div id="slide3">             content in here          </div>     </form>  </div> 

i have 3 divs inside form slide across once input fields within div have been completed. here attempted jquery:

jquery('#signupforminner input, #signupforminner select').change(function(i, v) {         var parentdivid = jquery(this).parent().attr('id');         jquery("#" + parentdivid + " input, #" + parentdivid + " select").each(function(i2, v2) {             if(jquery(v2).attr('value') == "") {                 var completedinputs = false;             } else {                 var completedinputs = true;             }                        });         alert(completedinputs);     }); 

what trying here when user changes element of form jquery check see if other elements within div of form have values too, , if so, said before, allow them press button slide next div in, containing more elements of form.

as can see setting variable called completedinputs true or false dependent on whether other elements within div have been completed keep on getting error saying:

referenceerror: completedinputs not defined [break on error]     alert(completedinputs); 

i can't seem solve define variable whether true or false not sure why saying undefined.

can see going wrong?

scope problem - define completedinputs outside of .each()

var completedinputs; jquery("#" + parentdivid + " input, #" + parentdivid + " select").each(function(i2, v2) {             if(jquery(v2).attr('value') == "") {                  completedinputs = false;             } else {                  completedinputs = true;             }                }); alert(completedinputs); 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -