0

I have a feedback form and I am replicating some code to check for values in text inputs and textareas. I have a name field and a feedback field. The errors hide on document load and at the start of a click function The name one shows as expected, but I cannot get the feedback one to show.

I set the errors to show on document load but hide onclick and I could get the feedback error to show if I filled in the name(the name error would hide, as expected).

HTML form.

<div class="slide-out-div">
 <h3>Give us Feedback</h3>
 <a class="handle" href="#">Content</a>
 <p>We would love to hear your ideas to make the site more user-friendly or efficient for your benefit.</p>
 <form name="feedbackform" id="feedbackform" action="" method="post">
    <label for="feedname">Name:</label>
    <input type="text" name="feedname" id="feedname" style="width:100%" /><br />
    <label class="error" for="feedname" id="feedname_error">Please insert your name.</label> <br />
    <label for="feedback">Feedback:</label><br />
    <textarea name="feedback" id="feedback" style="width:100%;height:150px;"></textarea>
    <label class="error" for="feedback" id="feedback_error">Please insert your some feedback.</label> <br />
    <input type="submit" value="Submit Feedback" id="feedbacksubmit" />
 </form>
 <div id="feedwrap"></div>
</div>

JQuery Process

$('#feedbacksubmit').click(function (e) {
 $('.error').hide();
 //Cancel the link behavior
 e.preventDefault();

 var name = $("input#feedname").val();
 if(name == ""){
  $("label#feedname_error").show();  
  $("input#feedname").focus();  
  return false;
 }

 Var feedback = $("textarea#feedback").val();
 if(feedback == ""){
  $("label#feedback_error").show();  
  $("textarea#feedback").focus();  
  return false;  
 }

//process
return false;

});

Any help would be greatly appreciated.

2 Answers 2

0

It's becasue you are returning false as soon as you complete the validation of the name. That'll stop the execution of the function there and the second error message will not show up. May be you can write something like this.

$('#feedbacksubmit').click(function (e) {
 $('.error').hide();
 //Cancel the link behavior
 e.preventDefault();
 var returnvalue = true;
 var name = $("input#feedname").val();
 if(name == ""){
  $("label#feedname_error").show();  
  $("input#feedname").focus();  
  returnvalue = false;
 }

 var feedback = $("textarea#feedback").val();
 if(feedback == ""){
  $("label#feedback_error").show();  
  $("textarea#feedback").focus();  
  returnvalue = false;  
 }

//process
return returnvalue ;

});
2
  • When I click the button it runs the function again it only returns false if there is no data in the name - when I put data in name and nothing in feedback the feedback error should show. I can get near idendical code to work else where, I tried your example and I get the same results, Name error shows(when expected), feedback error does not show. Thanks for your input though.
    – liamfriel
    Apr 5, 2011 at 9:27
  • So the feed back error doen't show at all,ryt? Have you tried alert(feedback ==""); just to make sure that the execution reaches there and you are getting the alert message true if feedback textarea is empty..
    – Jishnu A P
    Apr 5, 2011 at 9:34
0

It appears that if I move the error above the textarea is shows but otherwise it does not, it must show but not visible to the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.