Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Javascript Help Needed : Alert(z) Works Fine But Document.write Not, please
sherifmayika
post Feb 4 2008, 06:50 AM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 23
Joined: 29-October 06
Member No.: 16,848



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

CODE
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
CODE
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

This post has been edited by pyost: Feb 4 2008, 03:07 PM
Go to the top of the page
 
+Quote Post
yordan
post Feb 4 2008, 09:46 AM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,045
Joined: 16-August 05
Member No.: 7,896



I just made a slight change to your topic title in order to make it more specific to your problems.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Feb 8 2008, 12:56 AM
Post #3


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



In your second function you have a typo in document,write(Z); simply replace it with the following code:
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:
CODE
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,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Getting Screen Resolution using Javascript.(8)
  2. How To Create A Popup Window With Javascript?(19)
  3. javascript vs java(12)
  4. Javascript: Disable Mouse Right-click In Browser(16)
  5. Best Way To Learn Javascript(9)
  6. Javascript: Text To Texbox And Back To Text(2)
  7. Dynamicdrive: Good Site For JavaScript Codes(5)
  8. Downloads With Javascript?(7)
  9. Javascript: Simple Slidedown Menu(2)
  10. JavaScript: Simple Dropdown Menu(1)
  11. Calling Of Functions Between Mulitple External Javascript Files(2)
  12. Javascript: Browser Detection Script(0)
  13. JavaScript: Hide And Show Any Element With CSS(5)
  14. Ever Needs To Find Out A Table Height Or With With JavaScript(2)
  15. Create And Import JavaScript Modules For A Large Script(2)
  1. Vertical Marquee Using JavaScript(0)
  2. JavaScript Frames & Querystring(4)
  3. JavaScript Off Redirect Script(2)
  4. I Need Help With Javascript.(7)
  5. Problems With Dynamically Loading Javascript(2)
  6. One Click To Copy Script(0)
  7. Add Text To Textarea(6)
  8. Javascript Question(4)
  9. Javascript: How Do I Create Embedded Pop-up Windows?(7)
  10. Problem With Javascript Alert();(9)
  11. Include Function For Javascript(7)
  12. Fun With Javascript And Forms(2)
  13. Javascript Changes Aren't Working.(6)


 



- Lo-Fi Version Time is now: 14th October 2008 - 03:45 AM