473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="submit Form()">3</a>
<a href="thispage& p=4" onClick="submit Form()">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.thefor m.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 2560
kk*****@gmail.c om 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="submit Form()">3</a>
<a href="thispage& p=4" onClick="submit Form()">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.thefor m.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("Locatio n: ".$_POST["gotourl"]);
exit;
}
}
?>

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

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

<hr>
<form action="test1.p hp" method="POST" name="myform">
<input type="hidden" name="formposte d" 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(aUR L){
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
2592
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 that follows C++ RAII pattern. Of course Python objects are not statics like in C++, but in C++ the auto_ptr class is used for enforcing this...
5
6088
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 of the screen. I want it to only extend as far as it needs to to nicely contain the content within (a couple of links). Is width: auto the wrong...
9
2496
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 auto-newline "minor mode" facility. If you could spare a little time, would you answer these questions, please: o Do you program with auto-newline...
20
2838
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
5053
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 do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which...
7
22678
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 be appreciated. Thanks, Brian
5
2474
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 primary key in the "suspended_table" is an auto incremented integer where as "live_table" primary key is just a standard integer. Here's the...
5
3252
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 I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what...
22
3038
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 like that: int main(char argc, char *argv, char *env) { try { auto Exception mainException(1); mainException.setErrNo(42);
21
6312
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
7692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7457
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7791
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.