Jump to content
xisto Community
sherifmayika

Javascript Help Needed : Alert(z) Works Fine But Document.write Not please

Recommended Posts

hi all,
I am facing problem in my javascript, any kind of help would be apreciated

function basicFiles(){//var Z = "";			for (i = 0; i < document.Form.regionlist.options.length; i++) {				var x = document.Form.regionlist.options[i].value;				var y = document.Form.regionlist.options[i].text;				var Z =  "regions" + "[" + x + "]" + " = " + y + ", ";				alert(Z); 			}				 }
this works well but the following returns only errors
function basicFiles(){//var Z = "";			for (i = 0; i < document.Form.regionlist.options.length; i++) {				var x = document.Form.regionlist.options[i].value;				var y = document.Form.regionlist.options[i].text;				var Z =  "regions" + "[" + x + "]" + " = " + y + ", ";				document,write(Z); 			}				 window.close(); }


thanks

sherif
Edited by pyost (see edit history)

Share this post


Link to post
Share on other sites

In your second function you have a typo in document,write(Z); simply replace it with the following code:

document.write(Z);
But, when you executes this function you got an error and only works one time, so if your intention is to concatenate all the elements (values and texts) of the select in one string and then write it to the document -your Z variable- change your function to:
function basicFiles1() {	var Z = new String("");	for (i = 0; i < document.Form.regionlist.options.length; i++) {		var x = document.Form.regionlist.options[i].value;		var y = document.Form.regionlist.options[i].text;		Z = Z + "regions" + "[" + x + "]" + " = " + y + ", ";	}	Z = Z.substr(0,(Z.length-2));	document.write(Z); 	//window.close();}
Hope it helps and is what you need.

Best regards,

Share this post


Link to post
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

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.