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

Assigning value

190 100+
i am not able to assign values ,can any one tell me whats wrong ....

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function changeMySrc(nm,act)
  3.       {
  4.         alert("hi"+ nm );
  5.         if(act == 1)
  6. {
  7.  
  8.          dc = "document.getElementById('"+ nm +"')";
  9.          dc.src="http://bytes.com/images/delete.gif";
  10.           alert(dc.src);
  11.          hd_val = "documnet.getElementById('chk[" + nm + "]')";
  12.          hd_val.value = "0" ;
  13.          alert(hd_val.value);
  14.  
  15.  
  16.  
  17.          }
  18.         else if (act == 0)
  19.         {
  20.  
  21.          dc="document.getElementById('"+nm+"')";
  22.          dc.src="http://bytes.com/images/addbutton.gif";
  23.          alert(dc.scr);
  24.          hd_val = "document.getElementbyId('chk["+ nm+"]')";
  25.          hd_val.value = "1";
  26.          alert(hd_val.vlaue);
  27.  
  28.         }
  29.     }
  30.  
  31. </script>
when i want to print values is gives me "undefined"
Dec 5 '08 #1
20 2117
RamananKalirajan
608 512MB
Are u getting the alert at the line no: 4

and in the line alert(dc.scr); it must be src not scr.

Can u please post the whole code.

Regards
Ramanan Kalirajan
Dec 5 '08 #2
Shalini Bhalla
190 100+
actually my code is too big . what i want to do is that i have a folder name , image showing folder is selected or not and a hidden box .

now if folder is selected , its showing "-" hidden box value is 1 image and now i want to deselect it . when i deselect it , image should chamge to "+" and hidden box value should become "0";

this is what i am trying to do but not getting sucess ....
Dec 5 '08 #3
acoder
16,027 Expert Mod 8TB
Your code has quite a number of errors. For example, this line
Expand|Select|Wrap|Line Numbers
  1. dc = "document.getElementById('"+ nm +"')";
should be simply
Expand|Select|Wrap|Line Numbers
  1. dc = document.getElementById(nm);
No quotes needed. Also check for spelling mistakes.
Dec 5 '08 #4
Shalini Bhalla
190 100+
thanks its working

but now the problem is that its only changing image once.
Dec 5 '08 #5
acoder
16,027 Expert Mod 8TB
Have you made changes to the rest of your code? Post your updated code.
Dec 5 '08 #6
Shalini Bhalla
190 100+
Thanks alot , its working perfactly
Dec 5 '08 #7
acoder
16,027 Expert Mod 8TB
Excellent. Glad you managed to get it working.
Dec 5 '08 #8
Shalini Bhalla
190 100+
Actually now further ....

i am displaying a hidden text box also with image , now i want that my value of hidden box also should reflected with the change of image ....

this is how my hidden box is coming from a database , i am making it an array because i want to apply batch updation for that further , but fisrt i want to manage value :

this is how hidden box is coming :

Expand|Select|Wrap|Line Numbers
  1. <? 
  2. include("conn.php");
  3. $userID = $_GET["q"];
  4. $qry = "select * from folder";
  5. $result=mysql_query($qry);
  6. echo "<table>";
  7. $i=0;
  8. while($row=mysql_fetch_array($result))
  9.     {
  10.      echo "<tr><td>".$row['folder_name']."</td>"; 
  11.      $qry1 = "select * from user_content_assign where folder_id = '".$row['folder_id']."' and user_id = '".$userID."'";
  12.      $result1=mysql_query($qry1);
  13.     $r = mysql_numrows($result1);
  14.     if($r <=  0)
  15.     {
  16.       echo "<td><img alt='not_selected' src='images/addbutton.gif' border='0' id = '".$row['folder_id']."' onclick='changeMySrc(this.alt,this.id);' ><input type='hidden' 
  17.  
  18. name='userid' value='".$row['userID']."'><input type='hidden' id='act[i]'  name='act[i]' value='".$row['active']."'><input type='hidden' name='fid[i]' 
  19.  
  20. value='".$row['folder_id']."'></td>";
  21.    }
  22.    else
  23.   {
  24.      while($row1=mysql_fetch_array($result1))
  25.       {
  26.         if($row1['active']  ==  1)
  27.            {
  28.              echo "<td><img  alt='selected' src='images/delete.gif' border='0'  id = '".$row['folder_id']."'  onclick='changeMySrc(this.alt,this.id);'  ><input type='hidden' 
  29.  
  30. name='userid' value='".$row['userID']."'><input type='hidden' id= 'act[i]'  name='act[i]' value='".$row1['active']."'><input type='hidden' name='fid[i]' 
  31.  
  32. value='".$row1['folder_id']."'></td>";
  33.            }
  34.           else 
  35.           {
  36.             echo "<td><img  alt='not_selected' src='images/addbutton.gif' border='0'   id = '".$row['folder_id']." onclick='changeMySrc(this.alt,this.id);'> <input type='hidden' 
  37.  
  38. name='userid' value='".$row['userID']."'><input type='hidden' id='act[i]' name='act[i]' value='".$row1['active']."'><input type='hidden' name='fid[i]' 
  39.  
  40. value='".$row1['folder_id']."'></td>";
  41.           }    
  42.         }
  43.     }
  44.         echo "</tr>";
  45.      }
  46. echo "</table>";
  47. ?>

And this is the java script i am using :

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function changeMySrc(alt,id)
  3.       {
  4.         alert("hi"+ alt );
  5.         if(alt == "not_selected")
  6. {
  7.  
  8.          dc = document.getElementById(id);
  9.          dc.src="http://bytes.com/images/delete.gif";
  10.          dc.alt="selected";
  11.          alert(dc.src);
  12.  
  13.      document.getElementById("act[id]").value="0";
  14.  
  15.  
  16.  
  17.  
  18.          }
  19.         else  if(alt == "selected")
  20.         {
  21.  
  22.          dc=document.getElementById(id);
  23.          dc.src="http://bytes.com/images/addbutton.gif";
  24.          dc.alt="not_selected";
  25.          alert(dc.src);
  26.  
  27.         document.getElementById("act[id]").value="0";
  28.  
  29.  
  30.  
  31.  
  32.  
  33.         }
  34.     }
  35.  
  36. </script>

i am trying to vhange value of hidden box , its showing me

act is not defined

any suggestions ?
Dec 5 '08 #9
acoder
16,027 Expert Mod 8TB
Avoid [] in IDs. Make sure the ID is unique too. You can set the ID to "act".$id where $id is a number to make it unique.
Dec 5 '08 #10
Shalini Bhalla
190 100+
i am still not getting how to change the value of hidden field "act" with respect of change in image .........
Dec 5 '08 #11
acoder
16,027 Expert Mod 8TB
You have this line:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("act[id]").value="0";
In your PHP code, change the IDs of the hidden fields to make them unique, so that you can access them in the JavaScript code with something like:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("actid1").value="0";
Dec 5 '08 #12
Shalini Bhalla
190 100+
i took array as i want to update multiple rows , if i change them to static values , i wont be able to update them in database
Dec 5 '08 #13
acoder
16,027 Expert Mod 8TB
That's for the name, not the ID.
Dec 5 '08 #14
Shalini Bhalla
190 100+
<input type='hidden' id='act".$i."' name='act[$i]' value='".$row['active']."'>

now i have done this but now what ? how to send value to call that value in javascript function ? So, that value can be changed......
Dec 5 '08 #15
acoder
16,027 Expert Mod 8TB
$i was only an example. You can use the img ID as part of the ID, e.g.
Expand|Select|Wrap|Line Numbers
  1. <input type='hidden' id='act".$row['folder_id']."' name='act[]' value='".$row['active']."'>
then to refer to the hidden field you can use "act"+id
Dec 5 '08 #16
Shalini Bhalla
190 100+
i am trying to ge value in javascript :

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function changeMySrc(alt,id)
  3.       {
  4.         alert("hi"+ alt );
  5.         if(alt == "not_selected")
  6. {
  7.  
  8.          dc = document.getElementById(id);
  9.          dc.src="http://bytes.com/images/delete.gif";
  10.          dc.alt="selected";
  11.          alert(dc.src);
  12.  
  13.          hd_val= document.getElementById("act"+id);
  14.         hd_val.value = "0" ;
  15.         alert(hd_val.value);


its giving me error , pls try to understand what i want ?
Dec 5 '08 #17
acoder
16,027 Expert Mod 8TB
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

Moderator.
Dec 5 '08 #18
acoder
16,027 Expert Mod 8TB
@Shalini Bhalla
Check the source as generated in the browser and post that here, i.e. the HTML code, not PHP.
Dec 5 '08 #19
Shalini Bhalla
190 100+
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title><MMString:LoadString id="insertbar/linebreak" /></title>
  6. <link href="css/admin.css" rel="stylesheet" type="text/css" />
  7. <script  src="selectuser.js"></script>
  8. <script src="call_insert.js"></script>
  9. <style type="text/css">
  10. <!--
  11. a:link {
  12.     text-decoration: none;
  13. }
  14. a:visited {
  15.     text-decoration: none;
  16. }
  17. a:hover {
  18.     text-decoration: underline;
  19. }
  20. a:active {
  21.     text-decoration: none;
  22. }
  23. -->
  24. </style>
  25. <!-- Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->
  26. <!-- Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->
  27. <!-- Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->
  28.  
  29. <script>
  30. function changeMySrc(alt,id)
  31.       {
  32.         alert("hi"+ alt );
  33.         if(alt == "not_selected")
  34. {
  35.  
  36.          dc = document.getElementById(id);
  37.          dc.src="images/delete.gif";
  38.          dc.alt="selected";
  39.          alert(dc.src);
  40.  
  41.          hd_val= document.getElementById("act"+id);
  42.         hd_val.value = "0" ;
  43.        alert(hd_val.value);
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.          }
  52.         else  if(alt == "selected")
  53.         {
  54.  
  55.          dc=document.getElementById(id);
  56.          dc.src="images/addbutton.gif";
  57.          dc.alt="not_selected";
  58.          alert(dc.src);
  59.  
  60.         }
  61.     }
  62.  
  63.  
  64.  
  65. </script>
  66.  
  67.  
  68. </head>
  69.  
  70. <body class="oneColElsCtr" >
  71.  
  72. <div id="container">
  73.   <div id="mainContent"><br />
  74.    <br />
  75.    <br />
  76.    <br />
  77.  
  78.    <span class="mainheading">Administration Module</span><br />
  79.    <span class="topnav"><br />
  80.    </span><a href="#" class="topnav">Create Folder</a><span class="topnav">&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</span><a href="#" class="topnav">Add Content</a><span class="topnav">&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</span><a href="#" class="topnav">Video Archive</a><span class="topnav">&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</span><a href="#" class="topnav">Create User</a><span class="topnav">&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</span><a href="#" class="topnav">Assign User</a><span class="topnav">&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#">&nbsp;</a></span><a href="#" class="topnav">Account Archive</a><span class="topnav">&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</span><a href="#" class="topnav">Account Overview</a><br />
  81.  
  82.    <br />
  83.    <br />
  84.    <br />
  85.    <br />
  86.    <br />
  87.    <br />
  88.    <br />
  89.    <div class="formContainer">
  90.      <form id="form1" name="form1" method="POST" action="video_archive.php"  >
  91.  
  92.        <table width="100%" border="0">
  93.        <tr>
  94.          <td width="45%" valign="top"><span class="mainheading2">Video Archive </span></td>
  95.          <td valign="top">&nbsp;</td>
  96.          <td width="45%" valign="top"><span class="mainheading2">Create User</span></td>
  97.        </tr>
  98.        <tr>
  99.          <td valign="top"><table width="100%" border="0">
  100.  
  101.                   <tr >
  102.              <td width="47%" class="foldername1"  ><b>Html</b></td>
  103.              <td width="53%"></td>
  104.         </tr>
  105.  
  106.            <tr>
  107.            <td colspan="2">test.html</td>
  108.            </tr>
  109.                     <tr >
  110.  
  111.              <td width="47%" class="foldername1"  ><b>Php</b></td>
  112.              <td width="53%"></td>
  113.         </tr>
  114.  
  115.            <tr>
  116.            <td colspan="2">test1.php</td>
  117.            </tr>
  118.                     </table> 
  119.            </td>
  120.  
  121.          <td valign="top">&nbsp;</td>
  122.          <td valign="top"><table width="100%" border="0">
  123.            <tr>
  124.              <td width="47%"><label>User Name</label></td>
  125.              <td width="53%"><input type="text" name="username" /></td>
  126.            </tr>
  127.            <tr>
  128.              <td><label>
  129.  
  130. Password             </label>
  131.                <label>               </label></td>
  132.            <td><input type="password" name="pass" /></td>
  133.            </tr>
  134.            <tr>
  135.              <td><label>
  136.              </label>
  137.                <label>Email ID              </label></td>
  138.  
  139.              <td><input type="text" name="email" /></td>
  140.            </tr>
  141.  
  142.            <tr>
  143.              <td><label>
  144. Company Name            </label></td>
  145.              <td><input type="text" name="company" /></td>
  146.            </tr>
  147.            <tr>
  148.              <td><div align="right">
  149.  
  150.              </div></td>
  151.              <td>
  152.                <div align="right">
  153.                  <label>
  154.                    <input type="submit" name="Submit" value="Submit" />
  155.                  </label>
  156.                </div></td>
  157.            </tr>
  158.          </table></td>
  159.  
  160.        </tr>
  161.        <tr>
  162.          <td valign="top" class="mainheading2">&nbsp;</td>
  163.          <td valign="top">&nbsp;</td>
  164.          <td valign="top" class="mainheading2">&nbsp;</td>
  165.        </tr>
  166.        <tr>
  167.          <td valign="top" class="mainheading2">&nbsp;</td>
  168.          <td valign="top">&nbsp;</td>
  169.  
  170.          <td valign="top" class="mainheading2">Assign User </td>
  171.        </tr>
  172.  
  173.  
  174.  
  175.        <tr>
  176.          <td valign="top" class="mainheading2">&nbsp;</td>
  177.          <td valign="top">&nbsp;</td>
  178.          <td valign="top" class="mainheading2"> 
  179.         <select name="select"   onchange="showUser(this.value)">
  180.      <option value="Select" selected >Select User</option>
  181.  
  182.                       <option value = 1 >abc</option>
  183.                       <option value = 2 >hij</option>
  184.                       <option value = 3 >shalini</option>
  185.                       <option value = 4 >fdgvfd</option>
  186.                       <option value = 6 >neeta</option>
  187.                     </select></td>
  188.  
  189.        </tr>
  190.        <tr>
  191.          <td valign="top" class="mainheading2">&nbsp;</td>
  192.          <td valign="top"></td>
  193.          <td valign="top" class="mainheading2"><table width="323">
  194.            <tr><td width="241">
  195. <div id="txtHint"></div>
  196. </td></tr></table></td>
  197.        </tr>
  198. <tr><td><input  type='submit' value='Assign'  name='assign'>
  199.  
  200.      </table>
  201.  
  202.      </form>
  203.      <br />
  204. </div>
  205. <br />
  206.  
  207.    <!-- end #mainContent -->
  208.   </div>
  209. <!-- end #container --></div>
  210. </body>
  211. </html>
  212.  
Dec 5 '08 #20
acoder
16,027 Expert Mod 8TB
Are you sure you've got the right page? Where's the image and hidden fields?
Dec 5 '08 #21

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

Similar topics

1
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not...
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
3
by: Ricky W. Hunt | last post by:
How does VB.NET determine comparing vs. assigning? For instance, if "checkbox1.checked = True" it only checks the value but leaves it as it whereas if you have "checkbox1.checked = True" by...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
6
by: BobRoyAce | last post by:
In my property declaration, shown below, is it correct to assign _DeptID = Value like I would have if it was just a plain ole Integer, or is this like setting two objects equal to each other where...
25
by: Sourav | last post by:
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p);
8
by: getmeidea | last post by:
Hi, I am using JDK 1.5. I have a program like this. Here i am directly assigning value to one object. It does'nt give me any compile time or run time error. In java we dont have access to any...
37
by: miken32 | last post by:
In PHP, if a function returns an array it's fairly common to capture its return values like this: <?php list($foo, $bar, $baz) = some_function_that_return_an_array(); ?> In Javascript, would...
1
by: The Pythonista | last post by:
I've been wondering for a while about whether assigning to __class__ is bad form or not. Specifically, I mean doing so when some other method of implementing the functionality you're after is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.