0

I have a simple javascript function that shoud insert a value in the cell when the value in the dropdown list changes. Dnt knw the reason why its not working.

<script type="text/javascript"> 
function displaytaskid() { 
    var id=document.getElementById(dropdown).value; 
    document.getElementById(task_id1).value=id; 
} 

</script>

        <td id ="task_id1"></td>
<td name = "task_id[]"  id="dropdown" onchange="displaytaskid()" ><select name="task_id">
	<option value=""></option>
	<?php
  
  	while($lp_row = pg_fetch_assoc($res2))
	{
  		$val = $lp_row["task_id"];
  		$caption = $lp_row["task_description"];
  		if ($row["task_id"] == $val) {$selstr = " selected"; } else {$selstr = ""; } ?>
		<option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo $caption ?></option>
		<?php }  ?></select>
    	</td>

Many Thanks

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by mick_sp
0

change this line:

document.getElementById(task_id1).value=id;

into

document.getElementById("task_id1").value=id;

you put task_id1 in there like it where a variabel, but it's a string

Michael

Edited by mick_sp: n/a

0

you have the same bug in de line above:

var id=document.getElementById(dropdown).value;

should be

var id=document.getElementById("dropdown").value;

Michael

0
document.getElementById(task_id1).value=id;

is also not right. should be

document.getElementById(task_id1).innerHTML=id;

Michael

0

tried every combination but doesnt work. I am not sure whether is is taking the value from the dropdown correctly or not.

<script type="text/javascript"> 
function displaytaskid() { 
    var id=document.getElementById("dropdown").value; 
    document.getElementById("task_id1").innerHTML=id;
} 
</script>

tried other combination also but no result

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

0

tried every combination but doesnt work. I am not sure whether is is taking the value from the dropdown correctly or not.

<script type="text/javascript">
function displaytaskid() {
var id=document.getElementById("dropdown").value;
document.getElementById("task_id1").innerHTML=id;
}
</script>

tried other combination also but no result

Try an alert to make sure:

<script type="text/javascript"> 
function displaytaskid() { 
    var id=document.getElementById("dropdown").value; 

alert(id);
// OR, to make sure your getElementById works: 
alert(document.getElementById("dropdown").length); // should be 1

    document.getElementById("task_id1").innerHTML=id;

alert(document.getElementById("task_id1").length); // should be 1

} 

</script>

You can also use firebug, the firefox plugin to debug javascript. works really great!

succes
Michael

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.