JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 28th, 2003, 08:27 AM
Evil_homer Evil_homer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 5 Evil_homer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
using JavaScript for form submit

Hi,

Im trying to create a form with two hyperlinks, which when clicked submit the page and pass different values to the page.

so far i have:

<form name="change_record" action="record_update.php" method="post" autocomplete="off">

<a name="edit" href="javascript:document.change_record.submit();">Edit</a>
<a name="delete" href="javascript:document.change_record.submit();">Delete</a>
</form>

As u can see, the posting to page is a php page. In that page i then want to be able to test which link was selected by using the post variables. eg

if(isset($HTTP_POST_VARS['delete'])) { //delete record }

However this doesn't work, as no post variable is recognised called delete. If i use a submit button instead however it works perfectly. eg

<input type="submit" name="delete" value="Delete"/>

Any ideas how i can get the hyperlinks to pass thier names as post variables, or a way i can detect which has been selected in php.

Thanks

Reply With Quote
  #2  
Old April 28th, 2003, 12:25 PM
asgeo1 asgeo1 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Victoria, Australia
Posts: 2 asgeo1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok. Well in that case you could try the onClick event instead. That could call a function which creates a hidden element with the appropriate value, and then submits the form.

<form name="change_record" action="record_update.php" method="post" autocomplete="off">

<a name="edit" href="javascript:void(1);" onClick="submitForm('Edit');">Edit</a>

<a name="delete" href="javascript:void(1);" onClick="submitForm('Delete');">Delete</a>

function submitForm(action){
document.all.change_record.innerHTML = document.record.innerHTML + "<input type=hidden name=submit value='" + action +"'>";
document.change_record.submit();
}


Then you can just check so see which link was used to submit the form:

PHP Code:
if($_POST["submit"] == "Delete"){ 
//delete record 




hope that helps
-Adam

Reply With Quote
  #3  
Old April 29th, 2003, 12:57 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 9 m 52 sec
Reputation Power: 10
Send a message via ICQ to stumpy Send a message via MSN to stumpy
I use the same kinda method

Code:
<script language="Javascript">
  function procLink(action) {
    document.foo.doThis.value = action
    document.foo.doThis.submit()
}
</script>
<form name="foo">
<input type="hidden" name="doThis" value="">
your links here.. call the JS function and pass 
it a value, edit or delete
</form>

btw - i noticed you have a space in the word "javascript" in your links. That may break things.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #4  
Old April 29th, 2003, 09:09 AM
Evil_homer Evil_homer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 5 Evil_homer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Thanks both, your methods work perfectly. Problem solved!


Reply With Quote
  #5  
Old October 21st, 2008, 02:42 AM
alikim alikim is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 1 alikim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 2 sec
Reputation Power: 0
well, i know it's a very old post but anyway i have this problem and i just want to say that if you modify your form object by adding a new property to it it seems to submit the form normally along with the submit button.

so, this form doesn't send submit button to POST

Code:
<script language="javascript" type="text/javascript">
	function js() {
	  document.form_name.submit();
	}
</script>


and this form does it

Code:
<script language="javascript" type="text/javascript">
	function js() {
	  document.form_name['weird'].value = '';
	  document.form_name.submit();
	}
</script>


i'll appreciate any comments about this

Reply With Quote
  #6  
Old June 29th, 2009, 06:27 PM
will1234 will1234 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 will1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 39 sec
Reputation Power: 0
$_POST does not work, why

your code is great and actually i have copied it from somewhere else too but the problem is POST does not work, even though the form method="post". The data is actually send using GET method. Do you know there is a restriction on POST using Javascript. May be this point needs to be cleared out for new commers

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > using JavaScript for form submit


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
Stay green...Green IT