I have the following in a simple form;
<form method="post" action="inc/core.php">
<input type="textbox" name="lognick" value="samp" />
<input type="password" name="logpass" />
</form>
I'm trying to get their value through;
var logname =开发者_开发问答 $("input[name=lognick]").val();
var logpass = $("input[name=logpass]").val();
logname always returns "samp" (the default value) and logpass undefined. I also tried using .attr("value")
but it's the same outcome.
When trying to use it on a blank page it works flawlessly. Here's the whole onclick function; http://pastebin.com/pQiVAuEW
Thanks!
I can't replicate the problem and I am able to access the value fine. The password box has no value so it should be undefined.
See this JSFiddle.
Have you tried $('#some_id').val()
or document.getElementById("some_id").value
? If they don't work, are you calling the function in correct place? It can happen, that the code (JavaScript I suppose) is run in the writing phase of the form and not after you're typing the values.
精彩评论