Take a look at this html:
<head>
<title>Test page</title>
<script type="text/javascript">
function submitForm() {
document.getElementById("form2").submit();
}
</script>
</head>
<body>
<form id="form1" name="form1">
<input type="hidden" name="test1" value="test" />
<form id="form2" name="form2" action="http://google.com">
<input type="hidden" name="test2" value="nothing" />
</form>
</form>
Submit
</body>
Thing I want to do is submitting form2 located within form1 with a javascript. I want this to be done by submitForm() function. The problem is that it doesn't appear to work. I'm using FireFox for testing and always get an error which says that it's undefined. Does anybody know how I can get it working? Thanks in advance!
You can't nest HTML forms like that. End form1 before starting form2. Duplicate the hidden input if necessary.
Well, given that you have no element with the ID "xxx", I could see where your script might have some difficulty. Perhaps you mean "form2"?
Related
I am trying to hack a page that requires a "username" and "password". I have created a form and I think it looks good;
<form action="http://hackmefff.co/login">
<input type="hidden" name = "username" value="hacker">
<input type="hidden" name = "password" value="b678jk">
</form>
People have told me that my form looks good and that I need to create a request in javascript. I don't know how to create one because I just started learning javascript yesterday. I have searched on how to create a request of submit, and all I see is functions that look like they are making a form, which I already have, so am confused. How would I send a request to log me into a website, assuming that url exists, and both name and password are correct.
EDIT:
I have formatted the code below because I don't want the page to show any text at all even though am logged in, it should just be blank. But a test page shows that I didn't get logged in;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>Test page for your custom form</title>
<script type="text/javascript">
function submitform()
{
document.yourform.submit();
}
</script>
</head>
<body>
<form name="yourform" action="http://hackmefff.co/login">
<input type="hidden" name = "username" value="hacker">
<input type="hidden" name = "password" value="b678jk">
</form>
<input type='hidden' name='query' />
</body>
</html>
<html>
<head>
<title>Test page for your custom form</title>
<script type="text/javascript">
function submitform()
{
document.yourform.submit();
}
</script>
</head>
<body>
<form name="yourform" action="http://hackmefff.co/login" method="post">
<input type="hidden" name = "username" value="hacker">
<input type="hidden" name = "password" value="b678jk">
</form>
Search: <input type='text' name='query' />
Login
</body>
</html>
Note that I have modified your form slightly to include a name so that we can reference it from the JavaScript function.
This answer of course assumes that you have to use JavaScript.
You don't need Javascript for that, just add a submit-button to your form:
<input type="submit" value="Submit">
I have 2 HTML files like this.
parent.html
<form method='get' action=''>
<input type='hidden' name='something'>
<input type='button' name='submit' value='Submit' onclick='newwindow=window.open("child.html","popup","height=150,width=200");'>
</form>
child.html
Enter Something Here<br />
<input type='text' name='somethingelse'>
<input type='button' name='submit' value='OK'>
When the user clicks on Submit button in parent, a new popup window will show up and ask him to enter something.
Can anybody please tell me how can I transfer the value of input[somethingelse] from
child to input[something] and submit the form in parent after the user has clicked OK?
You can get a reference to the form in the parent window via window.opener.document, like this:
var form = window.opener.document.getElementById("theFormID");
(You'd give the form an ID, although there are other ways to do it.)
Then you can access the fields in that form, and of course set their .value property, and you can submit the form via its .submit() function.
But fair warning: Users don't like pop-ups. If there's any way you can just incorporate the other field into the form, I would recommend that instead.
Here's a full example: Live Copy | Source | Source of popup
The main page:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<form id="theForm" action="" method="GET">
<input type="text" id="theField" name="theField">
<br><input type="submit" value="Send" onclick="window.open('/urawum/1','','height=400,width=400'); return false;">
</form>
</body>
</html>
The popup:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<p>Please fill in more information:</p>
<input type="text" id="thePopupField">
<br><input type="button" value="Send Form" onclick="doTheSubmit();">
<script>
function doTheSubmit() {
var doc = window.opener.document,
theForm = doc.getElementById("theForm"),
theField = doc.getElementById("theField");
theField.value = document.getElementById("thePopupField").value;
window.close();
theForm.submit();
}
</script>
</body>
</html>
If you run that, you find that when you click Send on the main page, it does the popup. If you fill in a value in the popup and click Send Form, the popup disappears and the form is submitted. You can tell the form is submitted with the value because I've used method="GET" and so you can see theField=yourValue in the query string in the URL of the resulting page. For instance, if you type "my value" into the popup, you'll see the URL http://jsbin.com/abiviq/1?theField=my+value in the main page after the form submit. (But your form presumably uses POST rather than GET, I'm just using GET to demonstrate.)
$('#popupformid').submit(function() {
var myVar = $('#somethingelseid').val();
$('input:text.something').val(myVar);
document.getElementById("formID").submit();
});
Can someone tell me why this markup/script errors out and doesnt put "Waltdog" into the Hidden1 input field?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<script>
document.getElementById("Hidden1").value = 'Waltdog';
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="Hidden1" type="hidden" runat="server" />
Let me know if you see this!!! You crazy Texicans are harshing my Wednesday vibe! :)
</div>
</form>
</body>
Because your script runs before the element exists.
HTML (along with javascript in script tags) in is interpreted top to bottom, therefore when the script runs, the input element has not yet been created.
The solution is either
put the script in a function that runs when the page loads
put the javascript after the element
Put script node below input
<input id="Hidden1" type="hidden" runat="server" />
<script>
document.getElementById("Hidden1").value = 'Waltdog';
</script>
I am trying to run a Javascript redirection code on the Window Phone 7's in-app browser, but the redirection does not seem to occur at all.
Snippet:
<script type="text/javascript">
function sform() {
document.forms["frm"].submit();
}
</script>
</head>
<body onload="sform()">
<form action="https://payment-endpoint-url.com" method="POST" name="frm">
<input type="hidden" name="Ref_ID" value="***" />
<!--- some other data that varies depending on the transaction -->
</form>
</body>
I have tried every possible way to make a HTTP POST redirect using Javascript and have also tried a few IE-specific methods, but they do not work. Is there a workaround for this? Could it be a new security feature that disallows redirect?
This code seemed to work for me:
<html>
<head>
<script type="text/javascript">
function sform() {
document.getElementById("submit1").click();
}
</script>
</head>
<body onload="sform()">
<form action="https://payment-endpoint-url.com" method="POST">
<input type="hidden" name="Ref_ID" value="***" />
<input type="submit" value="Go" id="submit1" />
</form>
</body>
</html>
I have a form with only one file input and I want to auto submit the form every time when someone selects file. Now I use this code:
$(function(){
$("#fil1").change(function(){
$("#form1").submit();
});
});
but it works only for the first selection. When I select some other file the form is't submitted again! It seems the change function is called only for the first time! Can anyone help? I use jquery...
What version of jQuery are you using? I just tried the code below and it worked multiple times. Also wonder if it's your browser. I tried Chrome and IE 8.
<html>
<head>
<title>index.html</title>
<script type="text/javascript" src="js/jquery/jquery-1.5.1.min.js"></script>
<script type="text/javascript">
alert('hit');
$(function(){
$("#fil1").change(function(){
$("#form1").submit();
});
});
</script>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<label for="fileField"></label>
<input type="file" name="fileField" id="fil1">
</form>
</body>
</html>
hope this helps...