开发者

PHP form wont submit

I have a simple form:

<form name ="Add" action="Add-Results.php" method="post">
 <label for="name" class="smallfont">Name</label>
 <input type="text" name="name" size="30" />
 <label for="name_error" class="error">Please enter a name</label>
 <input type="image" name="submit" src="../Content/Images/login-submit.gif">
</form>

Which works fine until I add in the following jquery

开发者_开发百科
$(document).ready(function()
{
 $(".error").hide();
 $("input[name=submit]").click(function() 
 {
  $(".error").hide();
  var name = $("input[name=name]").val();

  if (name == "") $("label[for=name_error]").show();

 return false;
 });

});
</script>

When I put in the jquery nothing happens when I click the submit. When I take out the jquery the form posts without a problem. Any ideas?


if (name == "") $("label[for=name_error]").show();

Should be

if (name == ""){ $("label[for=name_error]").show(); return false}


Form will not be sent, becuase you used return false at the end of click handler - so you prevent default action to run. And submitting form is a default action made on click - and it won't be run. Try removing that line.


Maybe you could put all the logic in a function, and on the onclick event of the button call that function, like this:

function checkName() { var flag = true;

$(".error").hide();
var name = $("input[name=name]").val();

if (name == "")
{
    $("label[for=name_error]").show();
    flag = false;
}

return flag;

}

then

<input type="image" name="submit" onClick="checkName()" src="../Content/Images/login-submit.gif">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜