I am currently trying to get a value from a form in HTML, and I get the HTML by doing a GET request to a url, and then parse that HTML using jquery.
Here is my HTML that I am trying to parse through:
<!doctype html>
<title>Test</title>
<body>
<form name="guestform">
<input type="hidden" name="ip" value="198.168.123">
</form>
</body>
Here is the jquery I use to get the HTML and then try to parse it:
$.ajax({
type : 'GET',
url: "http://localhost:8000/test.html",
success: function(data){
var form = $(data);
var ip = $("input[name='ip']").find(form).val();
alert(ip);
}
});
The input element is within the form element so you need to call form.find(.....)
$.ajax({
type: 'GET',
url: "http://localhost:8000/test.html",
success: function (data) {
var form = $(data);
var ip = form.find("input[name='ip']").val();
alert(ip);
}
});
You are searching your main document for an input and then trying to find the HTML document you loaded via Ajax inside it. You want to reverse that.
$("input[name='ip']").find(form)
should be
form.find("input[name='ip']")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With