473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

How can i pass a parameter array from PHP to a Javascript function

Hello.

I have a Javascript function that validates an specific form. As
parameters this function receives an array of elements to be checked.
Depending on the form in cause, the array could have variable lenght.
I don't know how can i pass a dynamic array on 'onsubmit' event form
PHP code to a JavaScript function.
I would like to do something like:

<script>
function Valid_Form(ElementsArray)
{
alert (ElementsArray[0].value);
alert (ElementsArray[1].value);

return (true);
}
</script>

....

<?php
...
echo "<form method='post' action='?oper=confirm' onSubmit='return
Valid_Form(this.elements[0], this.elements[1])'>";
...
?>

But it don't work!
Anybody can help me please.

Thanks
Regards
Miguel
Jul 17 '05 #1
1 5925
Miguel wrote:
Hello.

I have a Javascript function that validates an specific form. As
parameters this function receives an array of elements to be checked.
Depending on the form in cause, the array could have variable lenght.
I don't know how can i pass a dynamic array on 'onsubmit' event form
PHP code to a JavaScript function.
I would like to do something like:

<script>
function Valid_Form(ElementsArray)
{
alert (ElementsArray[0].value);
alert (ElementsArray[1].value);

return (true);
}
</script>

...

<?php
...
echo "<form method='post' action='?oper=confirm' onSubmit='return
Valid_Form(this.elements[0], this.elements[1])'>";
...
?>

But it don't work!
Anybody can help me please.


That's because you're not passing an array, but rather a list of
parameters. To wrap it in an array, you need to add an Array
constructor, like so:

Valid_Form(new Array(this.elements[0], this.elements[1]))

- Rico
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
10
by: nospam | last post by:
Hello! I can pass a "pointer to a double" to a function that accepts double*, like this: int func(double* var) { *var=1.0; ... }
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
5
by: FrederikVds | last post by:
I have a function which can be called with an unlimited number of arguments. I want to call another function with exactly the same arguments. I know I can get the arguments in the arguments...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
3
by: QQ | last post by:
I have one integer array int A; I need to pass this array into a function and evaluate this array in this function how should I pass? Is it fine? void test(int *a)
2
by: SM | last post by:
Hello, Such a simple question and i can't find the answer(see code below). Here it is: I have a function: ini() In that function, i call a function (load_CDThumbnail) that creates an array and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.