Open a popup window on submit button - javascript

I have one form in JSP. I have some input fields in that page, when user types his values then he clicks submit so that values will be inserted into the database.
But my purpose is that when user clicks submit button then one new popup window will be generated and this new popup window will carry those values at the time of inserted values in parent window. Ex: first page: Insert.jsp and popup window: Verifyinsert.jsp. In Insert.jsp page 3 input fields are present such as roll number, student name, address. User will enter these 3 fields first on Insert.jsp page and then user will click submit on Insert.jsp page, then one new popup window(Verifyinsert.jsp) will be generated carrying values when user just has typed in Insert.jsp and in that Verifyinsert.jsp page, submit button is present and if user clicks submit then records will be inserted into database and if cancel button will be clicked on Verifyinsert.jsp then that popup window will be simply disappeared. How to do it?
Any help is much appreciated.

Use onSubmit event
<html>
<head>
<script type="text/javascript">
function greeting(){
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br />
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Are you asking how to show popup window? Should it be js popup, with no page reload, or separate browser tab? For former we use jqModal library, examples. When user clicks on Submit button you need to display that popoup. When user clicks on Send button on that popup you need to get all values and send them to the server. There are a couple of way to do that too :)

Open a popup window in the submit of your Insert.jsp using
window.open("../insert.jsp?param1=xx&&pram2=cc")
you can send the parameters as append to the url of new window like above.
In the submit of Verifyinsert.jsp , you can call a parent page java script usign
window.opener.saveValue()
which is a javscript function in your parent page to save values to database .
Close your popup after saving .

Related

Is `<form target="_self">` acts like `location.replace()` that won't show in browser history?

I have a hidden page immediately submit form looks like this
<form
target="_self"
id="__ecpayForm"
method="post"
action="MY_API_DOMAIN"
></form>
<script>
document.getElementById("__ecpayForm").submit();
</script>
My form will redirect the user to other page.
However, some user will press previous page button on their phone, and then the form submits again!
But some users don't have the issue.
Why is this happening?
How can I make sure when the user presses the previous button, they won't navigate to this hidden page?

Loading window in classic asp

I have a button in the form in a page1.asp.
I am getting getting response from page2.asp after form submission.
It is take sometime for processing data in page2.asp.
User stays at page1 and clicking the button again and again.
so I want to have an "Loading window" while data processing and user could not click the Button again.
please help me to get this done.
Thanks in advance.
AGM Raja
You can use submit button's "onclick" event both to disable the button (so user won't be able to click it again) and to display "Loading..." message to the user.
At the very simplest you can display the message in the button itself, e.g.
<input type="submit" value="submit" onclick="this.disabled=true;this.value='Please wait...'" />
Demo: http://jsfiddle.net/t4f3T/
UPDATE
I don't know why it worked in my own tests, but Shadow Wizard pointed errors of my way: Form will not be submitted by disabled button, you have to add form.submit() yourself:
<input type="submit" value="submit" onclick="this.disabled=true;this.value='Please wait...';form.submit()" />
Demo 2: http://jsfiddle.net/t4f3T/2/

After clicking submit button the details entered by user has to be shown in another registration form

I created a HTML Registration page using HTML5 and Javascript its worked but after clicking submit button i have to show the details entered by the user in the another registration form (which is hidden on the same page before clicking submit button). once u have clicked submit button then that registration form has to be shown and the details which we entered also has to be shown.
If you have in first page fields with name "field1", "field2", "field3" etc
like -
<form action='page2.html'>
<input type='text' name='field1'>
<input type=submit>
</form>
In page2.html, get the parameters of GET request by javascript.
You can print the form values by using the function get(parameter) like - get("field1");
<script>
function get(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
</script>
In page1, you entered
<script>
document.write(get("field1"));
</script>
You can see it working here
But it is always better to use server side programing like php jsp asp etc. if you want to keep record for the fields and use it

html submit pressed and refresh

i've got a webpage with a form that has a dropdown selection and a submit button. the page also has a auto refresh function (every 10 secs) to retrieve and display the latest information from the server. when the submit button is clicked, a confirm alert popups with a yes/no option. user then select yes to submit the information to the server. the submission to server works
if the submit is clicked at the same time as the refresh occurred, the confirm dialog box popup but the form information is not submitted. is the confirm box still tied to the form?
here is my code. it may not be exactly the same because im my codes are offline but the geess is
<html>
<head>
<script type="text/javascript">
function confirmSubmit(message)
{
var ans = confirm(message);
if (ans == true)
{
return true;
}
else
{
return false
}
} //end of function
</script>
</head>
<body>
<form name="myForm" method="GET" action="GET">
<input type="submit" name="btnSubmit" value="submit" onclick="javascript:confirmSubmit()" />
</form>
</body>
</html>
The best thing would be to get rid of the auto refreshing so you don't have to worry about the form not being submitted. use AJAX instead to get new information that needs to be updated, this way the page doesn't need to refresh.
If for whatever reason you don't want to remove the auto-refreshing, what I would do is:
where ever you do the auto refreshing, check if the dropdown/form is being shown, and if it is, don't auto refresh.

Can a local page accept text value and open new tab at Internet URL with value as parameter?

An Internet site has URL like www.manyresultpages.net/cgi-bin/search.cgi?recnum=7777&
Can I make my Dad a local static html page (for his PC) with one input field and a submit button, that will modify the above URL, replace "7777" with the input text and open the new URL in a new tab on button click?
I'm HTML-challenged, googled for 45 mins without getting far. Did learn jsfiddle.net is down. Can load jQuery if that would help.
Yes. Use method="get" in the form to place the form data in the URL, use an input field with name="recnum" to get the right name for the form data, and use target="_blank" in the form to open the page in a new window/tab:
<form method="get" target="_blank">
<input type="text" name="recnum"/>
<input type="submit"/>
</form>
Note that you can't control whether the page is opened in a new window or a new tab, as that is a user preference in the browser.

Categories