By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,948 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,948 IT Pros & Developers. It's quick & easy.

Assigning value

100+
P: 190
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
Share this Question
Share on Google+
20 Replies


RamananKalirajan
100+
P: 607
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

100+
P: 190
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
Expert Mod 15k+
P: 16,027
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

100+
P: 190
thanks its working

but now the problem is that its only changing image once.
Dec 5 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Have you made changes to the rest of your code? Post your updated code.
Dec 5 '08 #6

100+
P: 190
Thanks alot , its working perfactly
Dec 5 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Excellent. Glad you managed to get it working.
Dec 5 '08 #8

100+
P: 190
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
Expert Mod 15k+
P: 16,027
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

100+
P: 190
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
Expert Mod 15k+
P: 16,027
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

100+
P: 190
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
Expert Mod 15k+
P: 16,027
That's for the name, not the ID.
Dec 5 '08 #14

100+
P: 190
<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
Expert Mod 15k+
P: 16,027
$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

100+
P: 190
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
Expert Mod 15k+
P: 16,027
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
Expert Mod 15k+
P: 16,027
@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

100+
P: 190
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
Expert Mod 15k+
P: 16,027
Are you sure you've got the right page? Where's the image and hidden fields?
Dec 5 '08 #21

Post your reply

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