473,804 Members | 3,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

36 New Member
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. {?>
  3.  
  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
  9.  
  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 4971
Dormilich
8,658 Recognized Expert Moderator Expert
of course you have to give out unique ids to get it working.
Sep 30 '09 #2
tarunkhatri
36 New Member
Yeahh Dormi I know tht. But I really dnt knw how to change my code to do that.
Sep 30 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
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
tarunkhatri
36 New Member
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
Dormilich
8,658 Recognized Expert Moderator Expert
how much do you know about DOM?

(you have 2 td per tr?)
Sep 30 '09 #6
tarunkhatri
36 New Member
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
Dormilich
8,658 Recognized Expert Moderator Expert
@tarunkhatri
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
the DOM IDL
Sep 30 '09 #8
tarunkhatri
36 New Member
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
Dormilich
8,658 Recognized Expert Moderator Expert
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

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

Similar topics

4
2812
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 get the developer assigned to that project (tp_assigned_to). Then, when I get the developer, I need that to be redirected to a second page. Example Code: ...... function getProject(){ //I know that this gets the selected value of the dropdown
3
1458
by: DaveF | last post by:
I need to capture a selected value of the onchange dropdown and put it in a textbox??? -- Dave
1
1358
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 the value is 'X' then, make certain other form fields visible, otherwise hide them.
0
3459
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 close to the same time. The code example below works however, while it is running if another cell is changed, it overrides it. DataGridViewRow row; DataGridViewCell dataCell; private void dataGridView1_CellValueChanged(object sender,
0
1570
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 might be "111,222,333,444". Instead of displaying the whole string, I need to split the string by the comma delimeter and show each value long enough so that every value will be
1
1857
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 do that? This is my working php code for only dropdown search. <table width="508" align="center" border="0"> <form> <tr> <td width="169"> <select name="users" onchange="showUser(this.value);"> <option...
1
1827
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 AJAX to do the same. Please help to pass the value for the second dropdown through AJAX only.
1
3481
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 display. but when i select Cheque on selection function work only for first row not working in other row. I am attaching the code snippet as well ... see if you can help ... <script language="javascript"> function handleOther(val){ if(val ==...
1
2862
by: lipton | last post by:
how can i compare a mysql table feild value with selected redio button value with php
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.