I have a PHP file at the bottom of my markup that gets generated to output my JavaScript (many reasons for this…). In the markup, though, I have a form whose input values are stored within an array. I need to pass this array to a JavaScript function that gets executed upon FORM SUBMIT.
Inside the form tag, would I include an onsubmit attribute like so?
<form action="index.php" [B]onsubmit="return validate(this,new_chart);"[/B] method="post">
In my mind, this would call the validate() function that accepts 2 arguments (this, which represents the form being processed and the array being passed into the function).
The problem I’m running up against in all this is that Firebug keeps telling me that the array I’m trying to pass isn’t defined. I’m thinking that’s because I’m not passing the array properly or that it’s because the JavaScript function isn’t understanding that what I’m trying to pass is even there–of which my understanding of JavaScript in general shines.
The JavaScript that’s intended to handle the array is the following:
<?php
echo '
function validate(thisform,array){
if(new_chart[email] !== NULL && new_chart[email] !== \\'\\'){
alert(new_chart[\\'email\\']);
}
}
';
?>
I think I need to tell this function that array is an actual array, but how? Something like “var new_array = for(x in array){iteration assignment}”?
How can I pass the array that’s created within the form over and into that JavaScript function?
Let me know if you’re lost–I can suck when explaining these things…