I'm going to try my hardest to try and explain what I'm trying to achieve essentially what I'm after is for the form to POST to the post_form_here.html and then to redirect the main page to redirect_main_page.html I need the form to post the values to the popout window and then to redirect the main page to the redirect page.
<form method="POST" onclick="window.open('POST_FORM_HERE.HTML', 'newwindow',
'width=500,height=500'); return true;" action="REDIRECT_MAIN_PAGE.HTML">
This is what I have so far however this posts the form to the redirect_main_page.html and not the post_form_here.html. Thank-you for any help and I hope I've explained what I'm trying to achieve well enough.
use target="_blank" in form
<form action="demo_form.asp" method="get" target="_blank">
</form>
If you want new window use like this
<form method="post"
target="new_popup"
action="https://www.google.co.in/"
onsubmit="window.open('about:blank','new_popup','width=500,height=300');">
<input type="text" />
<input type="submit" />
</form>
Try this
HTML
<form id="form">
<input type="text" name="name" >
<input type="text" name="age" >
<input type="submit">
</form>
JS
var form = $("#form");
form.on("submit",function(){
window.open("POST_FORM_HERE.html?" + form.serialize(), "newwindow", 'width=500,height=500');
window.location.href = "/REDIRECT_MAIN_PAGE.html";
return false;
})
Related
I've got on my index.php form with POST method.
Action is form.php, so it's different file, but I'm using iframe to show my result, still being at index.php.
One more thing that I need, is to show one of my text inputs, still on index.php, when I do click submit button. I've tried to use onClick action:
<script type="text/javascript">
function showamount()
{
var price = document.getElementById('amount').value;
document.getElementById("some_p").innerHTML = price;
}
</script>
<input type="text" id="amount" />
<input type="submit" value="Podlicz" onclick="showamount()" />
<p id="some_p"></p>
It does not work there, when submit button is dedicated to form, with an action (I suppose, because it works without form, when is pure like above)
What is wrong? Thanks!
Try this <form id="form" onSubmit="return showamount();" action="form.php" target="_blank">
That will open a new window to run the form.php and will also update current page with inputed value.
javascript
<script>
function showamount()
{
var price = document.getElementById('amount').value;
document.getElementById("some_p").innerHTML = price;
return true;
}
</script>
html
<form id="form" onSubmit="return showamount();" action="form.php" target="_blank">
<input type="text" id="amount" />
<input type="submit" value="Podlicz" onclick="showamount()" />
</form>
<p id="some_p"></p>
I am kind of new to javascript however I have created a submit form that I want to redirect me to a url based on form input. Here is my current code...
The issue I'm running into however is that the form is sending me the initial value rather than the updated form value (It is using "whatevs" no matter what).
HTML
<form id="Search-Form" onClick="genURL()"><label>Value: </label>
<input type="text" id="search" placeholder="Enter Value"></input>
<div id="search-buttons">
<input id="searchSubmit" value="whatevs" type="submit" tabindex="1" />
</div>
</form>
Javascript
function genURL() {
var searchSubmit = document.getElementById("searchSubmit").value;
window.location = "randomsite/view" + searchSubmit;
}
Add return and use onsubmit:
<form id="Search-Form" onsubmit="return genURL()"><label>Value: </label>
<input type="text" id="search" placeholder="Enter Value"></input>
<div id="search-buttons">
<input id="searchSubmit" value="whatevs" type="submit" tabindex="1" />
</div>
</form>
Revise function like so:
function genURL()
{
location.href = "randomsite/view" + document.getElementById("search").value;
return false;
}
If you were to use onclick, it would go on the button, not the form.
I want to use the return value of a JS function as the URL for a form get action. Is it possible or do I need to set the form attributes with a function call in the onSubmit attribute?
edit: this is basically what i want to do
<div class="search">
<form method="get" action="https://duckduckgo.com/" id="search-form">
<input id="searchbar" type="text" name="q" size="31" maxlength="255" value="" autofocus="autofocus"/>
</form>
<script type="text/javascript">
document.getElementById("search-form").action = "bang()";
</script>
</div>
the bang function is an implementation of the bang system from DDG in JS, so i can easily add bangs to a searchbox in my webpage.
You can use the onsubmit event for the form to set the action before the actual submit happens.
<form id="testForm" methods="get" action="#" onsubmit="setFormUrl()">
Search: <input type="text" name="q" />
<input type="submit" value="Go" />
</form>
function bang()
{
return "http://www.google.com";
}
function setFormUrl()
{
var url = bang();
document.getElementById('testForm').setAttribute('action', url);
}
I have multiple forms in my php file for different buttons. So, if I click on Back button, ramesh.php script should be called and so on. This is the code.
<form action="ramesh.php">
<input type="submit" value="Back" />
</form>
<form action="process.php" method="post">
<input name="rep_skyline" type="text" />
<input type="submit" />
</form>
<form action="update.php" method="post" >
<button type="submit">Update</button>
</form>
However, I need to pass some data to server from my client side on form submit just for the update button. I have a javascript function to send the data to server side as below.
<script type="text/javascript">
$(document).ready(function() {
$('form').submit(function(e) {
var mydata = 3;
if ($(this).is(':not([data-submit="true"])'))
{
$('form').append('<input type="hidden" name="foo" value="'+mydata+'">');
$('form').data('submit', 'true').submit();
e.preventDefault();
return false;
}
})
})
</script>
If I click on the update button, the javascript function is working fine. However, if I click on Back or Submit button, I should not be calling the javascript function. Is there someway to do this?
Give your form an id:
<form action="update.php" method="post" id="update-form">
Then use a more specific selector:
$("#update-form").submit(function() {
// Code
});
I'm not quite sure why you need JavaScript to dynamically add data to your form, however. You should just use an <input type="hidden" /> directly.
type=submit will always load the form's action. Try to specify wich form to submit.
<form name="backForm" id="backForm" action="ramesh.php">
<input type="submit" value="Back" />
</form>
<form name="form2" id="form2" action="process.php" method="post">
<input name="rep_skyline" type="text" />
<input type="submit" />
</form>
Now you can access the form via document.backForm or document.getElementById("backForm") and than use submit(); like document.getElementById("backForm").submit();
I have a form
<form method="post" id="ff">
<input type="name" id="aa" />
<input type="name" id="bb" />
Submit
</form>
Is it possible to post using the href ? I need to post the datas to href url.Is it possible?
Can someone help?
I dont want to use the normal action=
You can try this
<form method="post" action="http://www.example.php" id="ff">
<input type="name" id="aa" />
<input type="name" id="bb" />
Submit
</form>
<script>
function submitForm(){
$('#ff').submit();
}
</script>
Why don't you use
<form method="post" id="ff" action="http://www.example.php">
...
</form>
Yes, you can do this, but it will require JavaScript:
Submit
You could also write more complex JavaScript functions and call that.
Specify the target URL as the action attribute of the form:
<form method="post" action="http://www.example.php">
Strictly speaking, what you ask is possible but not pretty:
<a href="http://www.example.php"
onclick="var e=document.getElementById('ff').action=this.href;e.submit();return false">Submit</a>
I'd go for the action instead...
relace:
Submit
with:
Submit
<script type="text/javascript">
function frmsubmit(obj){
var url = obj.href;
document.getElementById('ff').action = url;
document.getElementById('ff').submit();
}
</script>
if you have more than one tag than use id and find it rather than by tag name