473,226 Members | 1,463 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,226 software developers and data experts.

Js function to change respecive cell value onchange selected value of dropdown value

Hi. I have a javascript function to change the value of the cell on chnage event of a dropdown list.My code is workin but the problem is that the value of the cell is chaning but not respective to the selected dropdown list( as there are 15 dropdown list and 15 cells), but only on the 1st cell. So need some identification for each cell. Can anyone help me just refine my code.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function displaytaskid(ths) { 
  3.     var id= ths.options[ths.selectedIndex].value;  
  4.     alert (id);
  5.     document.getElementById('task_id1').innerHTML=id;
  6. </script>
Expand|Select|Wrap|Line Numbers
  1. <?php for($count; $count <15; $count++)
  2. {?>
  4.     <tr>
  5.         <td id ="task_id1[]"></td>
  6. <td name = "task_id[]"><select name="task_id" id="dropdown" onchange="displaytaskid(this)">
  7.     <option value=""></option>5
  8.     <?php
  10.       while($lp_row = pg_fetch_assoc($res2))
  11.     {
  12.           $val = $lp_row["task_id"];
  13.           $caption = $lp_row["task_description"]; ?>
  14.         <option value="<?php echo $val ?>"><?php echo $caption ?></option>
  15.         <?php }  ?></select>
  16.         </td>
Sep 30 '09 #1
16 4920
8,658 Expert Mod 8TB
of course you have to give out unique ids to get it working.
Sep 30 '09 #2
Yeahh Dormi I know tht. But I really dnt knw how to change my code to do that.
Sep 30 '09 #3
8,658 Expert Mod 8TB
what about
Expand|Select|Wrap|Line Numbers
  1. echo "<td id=\"task_id_$count\">";

besides, you don’t even have to use ids, since the select and the td have the same parent.
Sep 30 '09 #4
THanks Dormi, sounds a good idea.. but then how to identify it by the js function(what change I need to do to my JS function) to identify each cell with the respective change in the dropdown list
Sep 30 '09 #5
8,658 Expert Mod 8TB
how much do you know about DOM?

(you have 2 td per tr?)
Sep 30 '09 #6
yes there are 2 td per tr.. In one td there is the cell where i want my value to be changed and in 2nd is the actual dropdown list. which is trigerrin the js function. A little bit about DOM. Whenevery this JS bit comes in my code i get confused as I m really not good at it.
Sep 30 '09 #7
8,658 Expert Mod 8TB
time to get better… if you want to advance in JS, you need to know DOM. because DOM is what makes modifying HTML documents easy.

first some stuff to read:
DOM Intro (there are further articles listed)
DOM Intro @ W3C

some technical stuff
the DOM Specifications
Sep 30 '09 #8
Thanks vry much Dormi. This wud be really helpful. I know I really have to read this otherwise I ll keep on hanging around. But still rgt now if u have a solution for above do let me knw.
Sep 30 '09 #9
8,658 Expert Mod 8TB
I have an idea.
Expand|Select|Wrap|Line Numbers
  1. parentNode.firstChild().nodeValue = this.value;
case closed*.

you need to know DOM to understand the meaning of that. and event listeners.

* – for me
Sep 30 '09 #10
Thanks for your effort.
Sep 30 '09 #11
8,658 Expert Mod 8TB
and now for a working (FF) example
Expand|Select|Wrap|Line Numbers
  1. function setTD()
  2. {
  3.     this.parentNode.parentNode.firstElementChild.textContent = this.value;
  4. }
  5. // addEventForEach() is a custom function
  6. document.getElementsByTagName("select").addEventForEach("change", setTD, false);
Sep 30 '09 #12
I have changed my code to below.. but still dosnt work.?? does any one has a solution
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function displaytaskid(ths,rowno) { 
  3.     var id= ths.options[ths.selectedIndex].value;  
  4.     alert (id);
  5.    document.getElementById('task_id_rowno').innerHTML= id;
Expand|Select|Wrap|Line Numbers
  1. <?php for($count; $count <15; $count++)
  2. {?>
  4.     <tr>
  5.     <?php echo "<td id=\"task_id_$count\">"; ?>
  6.     <?php
  7.        $conn = connect();
  8.      $res2 = sql_select1(); 
  9.          ?>
  11.     <td name = "task_id[]"><select name="task_id" id="dropdown" onchange="displaytaskid(this,\"$count\")">
  12.     <option value=""></option>5
  13.     <?php
  15.       while($lp_row = pg_fetch_assoc($res2))
  16.     {
  17.           $val = $lp_row["task_id"];
  18.           $caption = $lp_row["task_description"]; ?>
  19.         <option value="<?php echo $val ?>"><?php echo $caption ?></option>
  20.         <?php }  ?></select>
  21.         </td>
Sep 30 '09 #13
8,658 Expert Mod 8TB
JS, unlike PHP, does not search for variable names inside strings.
Sep 30 '09 #14
humm ok... I changed it to
Expand|Select|Wrap|Line Numbers
  1.  document.getElementById(rowno).innerHTML= id;
but still no result
Sep 30 '09 #15
8,658 Expert Mod 8TB
if rowno is not the ID then you have no target element.

note: can you see, how useful the DOM is?
Sep 30 '09 #16
Thanks Dormi...I got a way around passinf count variable was doin all the prob..Anyways thanks very much for ur help
Sep 30 '09 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Lisa | last post by:
I know this is supposed to be easy but I can't get this to work. I have a dropdown that pulls all the Projects (tp_title) available. All I want to do is get the ID (tp_id) of that record so I can...
by: DaveF | last post by:
I need to capture a selected value of the onchange dropdown and put it in a textbox??? -- Dave
by: David | last post by:
Hi, I have an asp page with a simple form. The form has a dropdown which is database fed. Once the user selects a value from the dropdown, I need some code to test the value selected. If...
by: =?Utf-8?B?QnJpYW5ESA==?= | last post by:
Hi I am trying to find a way to change the background color of a cell (flash or blink) when its value has changed (by user or data update). I need to be able to do this for more than one cell...
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I need to have a column in a gridview that cycles through a set of comma delimited values i.e. if you imagine a column where in one row the value might be "111,222" and in the next row it...
by: ghjk | last post by:
I have a drop down box and the test box for the search field. In there I user only dropdown box to search values from the DB. But now I want to pass text box value with dropdownbox value. How can I...
by: Shreenath A | last post by:
I am using two dropdown boxes in ASP. I want to pass the selected value of first dropdown to the QRY to fetch and display only those items which belongs to the first selected dropdown. I am using...
by: nawedita | last post by:
Hi I am facing a problem with my code .... this is what I am doing ... I am running this dropdown in while loop...and i want when i select Cheque then display textbox otherwise textbox not...
by: lipton | last post by:
how can i compare a mysql table feild value with selected redio button value with php
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.