954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dynamic ID

Hi,
I'm creating the layout for a dynamic webshop, all pictures are getting dynamic IDs to have their elements changed. I'm currently having errors with the code below and have no idea why.

the argument id is not null, however
document.getElementById(id) is. I don't understand how that can happen :S

This is my javascript code

<script type="text/javascript">
			function change_bg(id) {
				if(id != null && document.getElementById(id) != null) {
					document.getElementById(id+'bg').src='product_bg_big.png';
					document.getElementById(id+'fg').src='product_fg_big.png';
					document.getElementById(id).src='product_i_big.png';
				}
				else {
					confirm('');
				}
			}
			
			function change_bg_back(id) {
				if(id != null && document.getElementById(id) != null) {
					document.getElementById(id+'bg').src='product_bg.png';
					document.getElementById(id+'fg').src='product_fg.png';
					document.getElementById(id).src='product_i.png';
				}
				else {
					confirm('');
				}
			}
		</script>


This is my php code:

echo "<td>
<img id='product".$numProduct."fg' src='product_fg.png' alt='product_fg'  onmouseover=javascript:change_bg('product".$numProduct."') onmouseout=javascript:change_bg_back('product".$numProduct."')>
					</td>";


EDIT: what's even stranger is that it all works, when I leave out the if, I just have a FireFox Addon which showed me those errors.
Any help would be very well appreciated.
Thanks

brechtjah
Junior Poster in Training
92 posts since Nov 2008
Reputation Points: 26
Solved Threads: 9
 

Solved it myself

brechtjah
Junior Poster in Training
92 posts since Nov 2008
Reputation Points: 26
Solved Threads: 9
 

Hi,

I am facing the same problem.

<% String filedid="rescheddate"+batchId%>
<input type="text" id="<%=fieldid %>" name="<%=fieldid %>" value="<%=date %>" readonly="readonly">
<a href="#"><img alt="Update" src="../images/update.gif" name="update" width=62 height=15 onclick="reschedule_onClick('<%=batchId %>')" border=0></a>

in the javascript i want to retrieve the dynamic filed value. Below is my java script:

function reschedule_onClick(batchNo)
  {
	  var feildid = "rescheddate"+batchNo;
	  alert(feildid)// this alert is coming.
	  alert(document.getElementById(feildid).value);// here failed
  }

The second alert is not working for me.. How to get the dynamic fields value?
Please advice.

Thanks & regards,
NEL

nagendrage
Newbie Poster
1 post since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You