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

Recommended Answers

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

Jump to Post

you have the same bug in de line above:

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

should be

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

Michael

Jump to Post

All 6 Replies

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

Changes , but no result

you have the same bug in de line above:

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

should be

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

Michael

document.getElementById(task_id1).value=id;

is also not right. should be

document.getElementById(task_id1).innerHTML=id;

Michael

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.