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

Solved it myself

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.