Hi all.
I have a form, and several text and image links on it that should
submit the form with different actions.
I prepared a simple page with just the code that's not working.
PROBLEM: The form won't submit if the link is clicked, but will submit
if the SUBMIT button is clicked. I need to call a function to change
the form's action according to user's input before it is submitted.
Thanks in advance for any help.
The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Submit test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<script language="javascript" type="text/javascript">
function SendForm() {
d = eval('document.forms[0]');
d.action = 'http://localhost:8080/test.php';
d.testVar.value = 'new value';
alert(d.testVar.value);
d.submit();
}
</script>
</head>
<body>
<form name="form1" method="post">
<a href="#" onclick="SendForm(); return true;">Submit</a>
<input type="submit" name="submit" value=" submit ">
<input type="hidden" name="testVar" value="original value">
</form>
<?php
// Debug stuff START --------------------------------
// Echo time, to check if the form has been submitted
echo time() . '<br />';
// See what's inside POST
var_export($_POST);
// Debug stuff END ----------------------------------
?>
</body>
</html>