|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
|||
|
|||
|
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:
hope that helps -Adam ![]() |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
Thanks both, your methods work perfectly. Problem solved!
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > using JavaScript for form submit |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|