To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
I have tried the below on PHP forum but was told to try here. I have a select menu. When the user makes a selection from it, two separate textareas should be automatically populated with data from database query.
However, below not working. If I use only one array works fine for populating just one textarea.
Any ideas please? Thanks.
PHP Code:
<?php
// 1) Get all Investment Types
$query = "SELECT investment_type_ID, investment_type, inv_note, inv_note2 ".
"FROM investment_type";
$result = mssql_query($query) or die('Select Error');
You're passing id in both of them, and then setting the value of id in the function call I assume? Well I thinkthat's the problem. Both arrays are being set to the same value of id.
Where's the function calls? That'll tell us what is being passed
__________________
PHP builder Online Community Manager
But there's one function, so you're setting the value of id to the same selectedIndex value. Will that work the way you have the arrays setup? I didn't get to see the actual arrays.
__________________
PHP builder Online Community Manager
Well it depends, I can't see the arrays so I dunno. If you have 2 arrays but only one index for them, then they better have corresponding values in the same bucket. Say if your index = 2, then you better have the 2 pieces of info you want in the 3rd bucket of each array. Otherwise you have to rewrite this function so that the id isn't passed as an arg. or else pass 2 args, id and id1 or something like that. However, if u DO that, you have to set both values in the call.
__________________
PHP builder Online Community Manager
Well thats the php which will spit out the JS arrays. It'd be easier to diagnose if I saw the output.
But basically the issue is this, you have 2 arrays, but only one index. Therefore if you pass the value of that index in the function calls, you will end up getting the same number bucket of each of the 2 arrays. Is that going to do what you wish? I still have no idea what you're really trying to do here, but that's the 1st thing you need to tell me.
For example, if you need buck 2 of the 1st array, and bucket 6 of the 2nd array, then this approach will not give you that.
__________________
PHP builder Online Community Manager
<script language="Javascript">
// Define first array
var notes = new Array();
// Assign PHP value to Javascript array
var notes = '<?php print_r($javascript_array) ?>';
// Define second Array
var notes2 = new Array();
var notes2 = '<?php print_r($javascript_array1) ?>';
// Put all elements into a string
document.write(notes.join(","));
document.write(notes2.join(","));
Well there's still something I don't understand. If you're pulling data from a server, why is JS being used at all? It doesn't play nice with PHP. Do the entire thing in PHP. It'll work much better and be easier.
__________________
PHP builder Online Community Manager
My advice, ditch the JS altogether, and do this entirely with PHP. Post it back in the php section and someone will be able to help with it. Or, if you want to do it without refreshing the whole page, then your only recourse is AJAX, in which case you won't need PHP at all.
__________________
PHP builder Online Community Manager