473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

auto-submit problem

Situation :
- A form (method : POST, action : itself, onsubmit : alert 'Submit' )
- Got 2 submit button ( 'Save' , 'View')
- Got navigation 1|2|3|4

What I want to do :
- Once clicked on the navigation page, it will save the page without
need to click on 'Save' button. Currently, if i manually clicked on the
'Save' button; it will save the page.

What have I done :
- tried using js form.submit(); not submitted coz no alert comes out
- tried using js button.click(); submitted coz got the alert, but it
didnt trigger the function to Save the form.

The code :
<form method="POST" name="theform" action="this page"
onSubmit="alert('submitted')">
:
:
:
<a href="thispage&p=3" onClick="submitForm()">3</a>
<a href="thispage&p=4" onClick="submitForm()">4</a>
:
<input type="submit" name="mysave" value="Save Value">
<input type="submit" name="myview" value="View Mode">
:
</form>

<script>
function submitForm() {
var theobject = document.theform.mysave
theobject.click()
}
</script>

<?php
if ($_POST['mysave']) {
....tried echo something here also not printed anything...
}
?>

May anyone help me on this?..

Apr 10 '06 #1
1 2538
kk*****@gmail.com wrote:
Situation :
- A form (method : POST, action : itself, onsubmit : alert 'Submit' )
- Got 2 submit button ( 'Save' , 'View')
- Got navigation 1|2|3|4

What I want to do :
- Once clicked on the navigation page, it will save the page without
need to click on 'Save' button. Currently, if i manually clicked on the
'Save' button; it will save the page.

What have I done :
- tried using js form.submit(); not submitted coz no alert comes out
- tried using js button.click(); submitted coz got the alert, but it
didnt trigger the function to Save the form.

The code :
<form method="POST" name="theform" action="this page"
onSubmit="alert('submitted')">
:
:
:
<a href="thispage&p=3" onClick="submitForm()">3</a>
<a href="thispage&p=4" onClick="submitForm()">4</a>
This needs improvent, read on.
:
<input type="submit" name="mysave" value="Save Value">
<input type="submit" name="myview" value="View Mode">
:
</form>

<script>
function submitForm() {
var theobject = document.theform.mysave
theobject.click()
}
</script>

<?php
if ($_POST['mysave']) {
....tried echo something here also not printed anything...
}
?>

May anyone help me on this?..


Hi,

The problem with your setup is that you use a hyperlink, THAT REPLACES THE
WHOLE PAGE, and a FORM-action, THAT WILL REPLACE THE SAME PAGE.

I hightlighted the part that give you trouble. ;-)

So what you do need is:
1) A working form. (Which you made already)
2) A hyperlink that does something else than hyperlinking, namely:
a) remember the url
b) set it in a hidden var in the form
c) submits the form. (It won't follow the hyperlink)
4) The receiving scripts redirects to an url passed by the hidden var.

So solve your problem by making your hyperlink do nothing and let Javascript
set the URL as a hidden var in the form.
Then, when processing the form, check for the url, and redirect.

Here is an example/proof-of-concept, using PHP as serverside language:

Regards,
Erwin Moller
<?
// Received a form?
if (isset($_POST["formposted"])){
// process the form
$firstname = $_POST["firstname"];
// do your stuff here

// redirect?
if ($_POST["gotourl"] != "NA"){
// go there:
header("Location: ".$_POST["gotourl"]);
exit;
}
}
?>

<html>
<head>
<title>Test hyperlink</title>
</head>
<body>

Nav:
<a href="" onClick="submitAndGo('test1.php?p=1'); return false;">nav 1</a>
<br>
<a href="" onClick="submitAndGo('test1.php?p=2'); return false;">nav 2</a>
<br>
<a href="" onClick="submitAndGo('test1.php?p=3'); return false;">nav 3</a>
<br>

<hr>
<form action="test1.php" method="POST" name="myform">
<input type="hidden" name="formposted" value="y">
<input type="hidden" name="gotourl" value="NA">
firstname: <input type="text" name="firstname">
<br>
<input type="submit" name="mysave" value="Save Value">
<br>
<input type="submit" name="myview" value="View Mode">
</form>

<hr>

<hr>

<script type="text/javascript">
function submitAndGo(aURL){
document.forms["myform"].gotourl.value=aURL;
document.forms["myform"].submit();
}
</script>

</body>
</html>
Apr 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
9
by: Alan Mackenzie | last post by:
To all those who use (X)Emacs's CC Mode to edit C, C++, Java, Objective-C, Pike, AWK or IDL: To help direct the development of CC Mode, it would be useful to find out how people use the...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
7
by: Brian | last post by:
hello, I am looking for a way to auto refresh a web page that I created, but also let the user choose to stop the auto refresh. I can not figure out how to stop the auto refresh. Any help would...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.