Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>onChange Help

onChange Help

Evening,

I'm having some difficulty at the moment with a bit of javascript, I'm by no means an expert, but I'm having a go.

Right, I'm pulling some information from a database using PHP, I'm storing this in a javascript array. So it's a little like this:


var comments = new array();


Then the PHP puts the information in the array like so.


comments['1'] = "Comments Here";
comments['2'] = "Comments Here Also";


Now what I require is a function that will change the data when the corresponding option is selected in the dropdown list.


<select name="comments">
<option value="1">Change To comments['1']</option>
<option value="2">Change To comments['2']</option>
</select>


Whatever is selected needs to be displayed underneath the dropdown list.

Could anybody put me in the right direction please?

If somebody can write the function that works, I will chuck them a few quid/dollars via PayPal.

Thanks,
Karl

This may be some help:<script type="text/javascript">
var comments = new Array();
comments[0] = "Comments Here";
comments[1] = "Comments Here Also";
var x = 1;
function dwrt(x,sel) {
if(x == 1) { document.getElementById('ed').options[0]=null; }
document.getElementById('it').value=sel; // to textarea
document.getElementById('dsply').innerHTML=sel; // to division
}
function addOpts() {
var opt;
var swrt = document.getElementById('ed');
for (var i = 0;i < comments.length;i++) {
opt = document.createElement('option');
opt.text = comments[i];
opt.value = i+1;
try { swrt.add(opt, null); }
catch(ex) { swrt.add(opt); }
}
}
window.onload=addOpts;
</script>

<form name="fm" id="fm" method="post" action="" enctype="multipart/form-data">
<select name="ed" id="ed" size="1" onchange="dwrt(x++,this.options[this.selectedIndex].text)">
<option selected="selected">Choose One</option>
</select><br />
<textarea name="it" id="it" cols="30" rows="5"></textarea>
</form>

<div id="dsply"> </div>


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

HP sharpens blade PC l
Hyperthreading hurts s
can not call click() i
script does not work o
smart menu 
write to an html file 
FireFox doesn't recogn
Changing e.keyCode (e.
Clearing a range creat
UPDATE: My mouse over 

News Archive

onChange Help 
beforeload? vs onload.
Problem with document.
decreasing my javascri
Problem with \\ and \ 
how to stop scrolling?
Change Label Text Colo
Can I forward a page b
2 javascript functions
Validating a textbox 

Related stories:

beforeload? vs onload.
Problem with document.ignore in javascript
decreasing my javascript
Problem with \\ and \
how to stop scrolling?
Change Label Text Color and Its Shade of Disabled Buttons
Can I forward a page by the URL used to get to it?
2 javascript functions clashing...
Validating a textbox

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics