POST data to server window.onload - javascript

I would like to send data to a web page through javascript. The code below works, however only with chrome. For example Firefox the code does not work. Do you know another method to send data when loading page that works on all browsers?
<html>
<head>
</head>
<body>
<form name="FormType" method="post" action="/welcome.php">
<input type="hidden" name="var1" value="abc">
</form>
<script type="text/javascript">
function autoClick () {
document.forms["FormType"].submit();
}
window.onload = autoClick;
</script>
</body>
</html>

Related

How does this HTML method = "POST" tag work?

I recently started a project that was going to download some data from a certain site. Unfortunately, when I wanted to download html with r.text, I got this code instead of the code I expected:
<html>
<head>
<title>Working...</title>
</head>
<body>
<form method="POST" name="hiddenform" action="some link"><input type="hidden" name="wa" value="wsignin1.0" /><input type="hidden" name="wresult" value="some links tokens and certificates" /><input type="hidden" name="wctx" value="some link" /><noscript><p>Script is disabled. Click Submit to continue.</p><input type="submit" value="Submit" /></noscript></form>
<script language="javascript">
window.setTimeout('document.forms[0].submit()', 0);
</script>
</body>
</html>
When I open this html code in webbrowser it redirects me to a certain site.
Can I send request with python requests module that will work just like that ?
If I did not explain something enough, I would be grateful to write it in a comment.

Repopulating form fields with javascript

Hi Sorry I'm newbie in Javascript but I need to know how I can do to repopulate a form field when I have this kind of form :
I tried with this code(part) but it doesn't work,the file name is 'testjavascript.html'
<head>
<script language="javascript" type="text/javascript">
function updateUsername(){
var first = document.getElementById("first").value;
document.getElementById("first").value = first;
} </script>
</head>
<body>
<form action="action.php" method="post">
<input type="text" name="usename" value="" id="first" >
Link
<input type="submit" name="submit">
</form>
</body>
This behavior needs to be on the server side. When you change page, the browser will reload your javascript code and you will lose all references.

Post data doesn't work on firefox

Here is my code:
<body onload="ccform.submit();">
<form id="ccform" name="ccform" method="post" action="https://www.XXXX.com" runat="server">
<input type="hidden" name="id" value="XXX" />
.....
</form>
this works fine both on ie9 and chrome, but in the firefox, it stopped at the this page instead of posting to "https://www.XXXX.com".
then i changed the code to
<body>
<form id="ccform" name="ccform" method="post" action="https://www.XXXX.com" runat="server">
<input type="hidden" name="id" value="XXX" />
.....
</form>
<script type="text/javascript">
document.body.onload = ccform.submit();
</script>
it still worked on ie9 and chrome but not firefox. Does anyone know why? thanks
I agree with bfavaretto that it is strange to submit on page load.
If you want to submit when the document is ready, you can use jquery :
load jquery :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
and then post your form
<script>
$(document).ready(function(){
var form = jQuery("#ccform");
form.submit();
}
</script>

Firefox ignores JavaScript override of form submit

I have this code
<html>
<head>
<script type="text/javascript" src="my-search.js"></script>
</head>
<body onLoad="my_Init();">
<div>
<form name="id_msearchform" onsubmit="my_EventHandler_Action(); return false;">
<input type="text" name="id_searchphrase" value="example"></input>
<br><br>
<input type="submit" name="id_searchsubmit" value="Search"></input>
</form>
<br><br>
<div id="id_searchresults">No search done...</div>
</div>
</body>
</html>
I don't want the browser to request a new URL. That is why "onsubmit" has "return false;". This code works in Internet Explorer, but Firefox generates a new request. Any ideas what I am doing wrong?
FireBug changes between not wanting to acknowledge there is Javascript reference and showing the Javascript file without any errors... I will update this when i have more to add. I will try various thingsm e.g. try upload it to the net and see if FireFox behaves differently when not running JS on local disk.
Are you sure that you haven't got any errors?
I try with a simple html:
<html>
<head>
<script type="text/javascript" src="my-search.js"></script>
</head>
<body onLoad="my_Init();">
<div>
<form name="id_msearchform" onsubmit="my_EventHandler_Action(); return false;">
<input type="text" name="id_searchphrase" value="example"></input>
<br><br>
<input type="submit" name="id_searchsubmit" value="Search"></input>
</form>
<br><br>
<div id="id_searchresults">No search done...</div>
</div>
</body>
</html>
And a simple javascript called my-search.js in the same path of my html with the next code:
var my_Init = function(){
alert('Hello Onload');
}
var my_EventHandler_Action = function(){
alert('Hello OnSubmit');
}
And it works fine.
Can you show a live demo (with dropbox or something)?
Instead of using a submit button, try using a button and link the javascript function to that.

iframe loading problem in the jsp

<head>
<TITLE> Sample CIM Implementation </TITLE>
<script type="text/javascript">
function init(){
document.forms[0].submit();
}
</script>
</head>
<BODY onload="init()">
<iframe id="authpopup" src="https://test.authorize.net/profile/manage">
</iframe>
<form type ="hidden" method="post" name="iframepopup" id="formAuthorizeNetPage" style="display:none;">
<input type="hidden" name="Token" value="<%=token%>"/>
</form>
</BODY>
</HTML>
i have a jsp page in which iam loading a iframe. The iframe is getting refreshed continuolusly i actually don want the iframe to get refreshed. This seems to flicker
As soon as the page loads, you call init(), which submits a form. This causes the page containing the iframe to reload, and thus also causes the iframe to reload. The page then calls init() again (since it has just reloaded) and so on.
Don't do that.

Categories