Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer doesn't execute my script!

    Hello everybody!
    I wrote a script which have to replace a text with a form but, as it's is used to be, it works just on safari and firefox: i have just learned javascript no i'm not a master in compatibility tecniques... Please help me fixing the script:
    Code:
    var c = 0;	//Just a counting variable
    function change(element, mode) {
    		var node = window.document.getElementById(element);
    	if(c == 0) { inner = node; }
    	c++;
    	
    		var day = 31; //Will create a form
    		var month = 12;
    		var year = 2015;
    		days = null; months = null; years = null;
    		
    			var i = 1;
    			for(i = 1; i<= day; i++)	//Giorni
    			days = days + '<option value="' + i + '">' + i + '</option> ';	
    			for(i = 1; i<= month; i++)	//Mese
    			months = months + '<option value="' + i + '">' + i + '</option> ';	
    			for(i = 2009; i<= year; i++)	//anni
    			years = years + '<option value="' + i + '">' + i + '</option>';	
    		
    		//Write the form
    		var former = '<div class="selecter"><table><tr><td><select name="day[]">' + days + '</select></td><td>';
    		former = former + '<select name="month[]">' + months + '</select></td><td>';
    		former = former + '<select name="year">' + years + '</select></td><td><img src="theme/images/icons/back.png" onclick="change(\'' + element + '\', 2);" border="0" alt="" class="edit" /><img src="theme/images/icons/edit.png" onclick="document.edit.submit();" border="0" alt="" class="edit" /></td></tr></table></div>';
    		
    		parent = node.parentNode;
    		newform = document.createElement("form");
    		newform.style.display = 'inline';
    		newform.action = 'system/compile.php';
    		newform.name = 'edit';
    		newform.method = 'post';
    		newform.id = element;
    		parent.replaceChild(newform, node);
    		novoel = newform.appendChild(node);
    		
    		if(mode == 1)
    		newform.innerHTML = former;
    		else
    		{ // Rewrite the original code if required
    				parent = novoel.parentNode;
    				ripristino = document.createElement("h4");
    				ripristino.style.display = 'inline';
    				ripristino.id = element;
    				parent.replaceChild(ripristino, novoel);
    				ripristino.appendChild(novoel);
    				ripristino.innerHTML = inner.innerHTML;
    				ripristino.id = inner.id;
    				ripristino.onclick = inner.onclick;
    		}
    }

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    days = null; months = null; years = null;


    Try to initialize these variables to empty strings instead of null. When they are null you cannot concatenate anything to them.

    days = ""; months = ""; years = "";


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •