Re: Javascript and $_POST

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm no JavaScript expert, but I could maybe suggest an alternate method: use document.getElementById() or document.getElementsByName()

AFAIK, the direct document.xyz doesn't work exactly the same way accross browsers (if at all).

e.g. (WARNING! TOTALLY UNTESTED CODE!)

function checkInputValue(item,onError) {
   if (item = document.getElementsByName(item)[0]) {
      if (item.value != "") {
         return(true);
      }
   }
   alert(onError);
   item.focus();
   return(false);
}

function checkForm() {
   elements = new Array('cc_phone_number');
   errors = new Array('Please enter a phone number');

   for (i=0;i<elements.length;i++) {
       if (!checkInputValue(elements[i],errors[i])) {
           return(false);
       }
   }

   document.getElementsByName('inputForm')[0].submit();
}

Dan Shirah wrote:
Okay, I edited my page per some suggestions here. Below is what I now have:


<script language="JavaScript">
function checkForm() {

// ** START **
 if (inputForm.cc_phone_number.value == "") {
   alert( "Please enter a phone number." );
   inputForm.cc_phone_number.focus();
   return;
 }

******Lots of other checks here, just left out for length******

  document.inputForm.submit();
}

</script>
<title></title>
<LINK rel="stylesheet" type="text/css" href="../../CSS/background.css">
</head>
<body>
<div align="center"> <h2></h2>
  <h3>Submit a New Payment.</h3>
</div>
<form name="inputForm" action="save.php" method="post"
enctype="multipart/form-data">

******Lots of form data here******

<table align="center" border="0" cellpadding="0" cellspacing="0"
width="680">
<tr>
<td width="64" align="left"><a href="javascript:checkForm()"
title="Save">Save</a></td>
<td width="616" align="left"><a href="javascript:closeThis()"
title="Close">Close</a></td>
</tr>
</table>
</form>
</body>
</html>

Now when I submit my page it still perfroms all of the javascript checks
correctly, but once it gets to the document.inputForm.submit(); part it
returns the following error.

Error: Object doesn't support this property or method.
Code: 0



On 2/7/07, Paul Novitski <paul@xxxxxxxxxxxxxxxxxxx> wrote:

At 2/7/2007 01:34 PM, Dan Shirah wrote:
>I have a form that uses Javascript to validate form field entries, and if
>they are incorrect it returns an error to the user.
>
>After the Javascript processing is complete, it submits the form to my
save
>page. However it seems that once the processing is complete and it passes
to
>the save page, none of my $_POST variables are being passed.


Of course, all of your form fields need to be inside the same
<form></form> tags as your submit button.  The sample HTML you posted
did not indicate that you'd done this.

Regards,

Paul
__________________________

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux