Jump to content

Leading Zero Of Image Path Being Removed


johnnyg24
 Share

Recommended Posts

I am having a problem with image names that start with a zero. (i.e. 0109.jpg).It looks like the leading zero's are being removed when a script try's to append the image name to the end of the image path. I see this happening in FF.I can't remove the leading zeros from the file names because a script uses this number to fill out a form which is then being submitted to our server. If I remove the zero's, then our server won't know which product to return results for.My question is, does anyone know why the leading zeros are being removed and if so how can I fix it? ThanksScript:

function loadXMLDoc() {	var	url = "http://www.estout.com/xmlDocs/XML/BOOKS.xml";	var XMLHtppRequestObject = false;		if (window.XMLHttpRequest) {			XMLHttpRequestObject = new XMLHttpRequest();		} else if (window.ActiveXObject) {			XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");		}		if (XMLHttpRequestObject) {			//change xml.xml to what ever xml doc you need//			XMLHttpRequestObject.open("GET", url, true); 			XMLHttpRequestObject.onreadystatechange = function() {				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {					xDoc = XMLHttpRequestObject.responseXML;												//xDoc is now your .xml//					//place function to call here//										bookTable();					}			}			XMLHttpRequestObject.send(null);					}	}	function bookTable() {			var nr1 = 0;					 for (var i = 0; i < xDoc.getElementsByTagName("bk").length; i++) {				 if (xDoc.getElementsByTagName("cls")[i].firstChild.data == 11) 	{	 											lk = document.createElement("li");											e = document.createElement("a");				e.innerHTML = xDoc.getElementsByTagName("bkid")[i].firstChild.data + " " + xDoc.getElementsByTagName("bkde")[i].firstChild.data;					e.href = "java script:getBookImg("+ xDoc.getElementsByTagName("bkid")[i].firstChild.data +");";				lk.appendChild(e);							document.getElementById('trim').appendChild(lk);				nr1++										 }			 getBookImg('1219');			}				}	function getBookImg(id){	deleteRows(document.getElementById("img"));	imgRow = document.getElementById("img").insertRow(-1);	formRow = document.getElementById("img").insertRow(-1);		var cellA=imgRow.insertCell(0);	var cellAA=formRow.insertCell(0);		im = document.createElement("img");	im.src = "http://www.estout.com/Images/" + id + ".jpg";	im.setAttribute('width', 300);	im.setAttribute('height', 300);	cellA.appendChild(im);	fm = document.createElement("p");	fm.setAttribute('align', 'center');	fm.innerHTML = '<form id="bookSearch" name="bookSearch" method="post" action="/webwiz/wwiz.asp?wwizmstr=W_SKU_SEARCH"><input type="hidden" id="bookNumber" name="bookSearchText" class="inputInstructions"  value="Enter Book Number" /><input type="hidden" name="wwizmstr" value="W_SKU_SEARCH" /><input type="submit" name="bookSubmit" value="Goto Thumnails" /></form>';	cellAA.appendChild(fm);	document.bookSearch.bookSearchText.value = id;	}

example of XML:

<bks><bk><bkid>0109</bkid><bkde>TRIM-ART OF COLOR</bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0302</bkid><bkde>TRIM-ART OF COLOR </bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0303</bkid><bkde>TRIM-ART OF COLOR </bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0304</bkid><bkde>TRIM ART OF COLOR NATURALS</bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0315</bkid><bkde>TRIM-ART OF COLOR</bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0324</bkid><bkde>MANHATTEN STRIPES</bkde><bkfm>OTHF</bkfm><cls>1</cls></bk><bk><bkid>0325</bkid><bkde>INSIDE/OUTSIDE</bkde><bkfm>OTHF</bkfm><cls>1</cls></bk><bk><bkid>0404</bkid><bkde>INSIDE/OUTSIDE TRIM</bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0410</bkid><bkde>SUMPTUOUS SUEDES</bkde><bkfm>OTHF</bkfm><cls>1</cls></bk><bk><bkid>0424</bkid><bkde>TRIM-ART OF COLOR</bkde><bkfm>AOCT</bkfm><cls>11</cls></bk><bk><bkid>0425</bkid><bkde>TRIM-ART OF COLOR</bkde><bkfm>AOCT</bkfm><cls>11</cls></bk></bks>

Link to comment
Share on other sites

Where are the zeros getting stripped? Do the links contain the correct ID:e.href = "java script:getBookImg("+ xDoc.getElementsByTagName("bkid").firstChild.data +");";Does the getBookImg function get the correct ID, or is it already stripped by that point?

Link to comment
Share on other sites

When I hover over the link, FF shows that the correct id is beeing passed to the getBookImg() function. It appears to be stripped after getBookImg() is called. I placed an alert to show what parameter was passed after the call to that function and everything works fine as long as there isn't a leading zero in the image file name. What has gotten more strange is that after the first book listing, all books with a leading zero are passing a parameter that has no correlation to what number should be passed. Link to Page

Link to comment
Share on other sites

Instead of this:

	fm.innerHTML = '<form id="bookSearch" name="bookSearch" method="post" action="/webwiz/wwiz.asp?wwizmstr=W_SKU_SEARCH"><input type="hidden" id="bookNumber" name="bookSearchText" class="inputInstructions"  value="Enter Book Number" /><input type="hidden" name="wwizmstr" value="W_SKU_SEARCH" /><input type="submit" name="bookSubmit" value="Goto Thumnails" /></form>';	cellAA.appendChild(fm);	document.bookSearch.bookSearchText.value = id;

do this:

	fm.innerHTML = '<form id="bookSearch" name="bookSearch" method="post" action="/webwiz/wwiz.asp?wwizmstr=W_SKU_SEARCH"><input type="hidden" id="bookNumber" name="bookSearchText" class="inputInstructions"  value="' + id + '" /><input type="hidden" name="wwizmstr" value="W_SKU_SEARCH" /><input type="submit" name="bookSubmit" value="Goto Thumnails" /></form>';	cellAA.appendChild(fm);

Also add this to the top of getBookImg:id = new String(id);If all else fails, you can also just manually pad the left side with zeros until the length is 4.

Link to comment
Share on other sites

That works! Thank you. But could you please explain why only the images with a leading zero in the file name were causing a problem?
Because you were passing the parameter as a number rather than as a string and the browsers were interpreting the number 0915 as 915.Notice the different outputs of the following two alerts:
<script type="text/javascript">alert(0915);alert("0915");</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...