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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble writing to new window I'm creating with javascript, need help!

    Hi,

    I've just written a small snippet of Javascript code which is supposed to open a new window and then write a String to the new window. Some of the string was captured from a form in the window that is calling the new one.

    Since I couldn't get it to work, I went ahead and modified the code so that I'm just writing a plain string using double quotes. Here's my current line of code I'm using to write to the window:

    dispWin.document.write("my message");

    Here's the code so you can see the context.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Spokane Telephone Survey</title>
    <script language="javascript" type="text/javascript">
    	<!-- Hide script from older browers
    	function submitForm() {
    		dispWin = window.open('','Confirm Survey Results','toolbar=no,status=no,width=600,height=400');
    		var q1Ind = document.surveyForm.spend.selectedIndex;
    		var q1 = document.surveyForm.spend.options[q1Ind].value;
    		message = "How much do you spend on long distance each month?" + q1;
    		dispWin.document.write(message);
    		dispWin.document.write("my message");
    	}
    
    	-->
    </script>
    </head>
    
    <body>
    	<form id="surveyForm" onsubmit="submitForm()">
    	<div class="question">
    		How much do you spend on long distance each month?
    	</div>
    	<div class="answer">
    		<select name="spend">
    			<option value="" selected="selected">Select one...</option>
    			<option value="$10 or less">$10 or less</option>
    			<option value="$11 - $20">$11 - $20</option>
    			<option value="$21 - $30">$21 - $30</option>
    			<option value="$31 or more">$31 or more</option>
    		</select>
    	</div>
    	<div class="question">
    		Do you make mostly daytime or evening/weekend calls?
    	</div>
    	<div class="answer">
    		<select name="when">
    			<option value="" selected="selected">Select one...</option>
    	 		<option value="day">Day Calls</option>
    	 		<option value="evening">Evening/Weekend Calls</option>
    	 	</select>
    	</div>
    	<div class="question">
    		Please make any other comments you feel would be helpful in the space provided.
    	</div>
    	<div class="answer">
    		<textarea name="comments" cols="40" rows="6"></textarea>
    	</div>
    	<div class="processForm">
    		<input name="submit" type="submit" value="Submit" />
    		<input name="reset" type="reset" value="Reset" />
    	</div>
    	</form>
    </body>
    </html>
    When the new window pops up, nothing ever gets written to it. Viewing the source just shows a blank HTML page with just the very barest of tags (html, head, body).

    Not sure where I'm going wrong, but I am not having any luck figuring it out. I'm hoping someone can point me to where my problem is at.

    David

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Spokane Telephone Survey</title>
    <script language="javascript" type="text/javascript">
    	<!-- Hide script from older browers
    	function submitForm() {
    		var q1Ind = document.forms[0].spend.options.selectedIndex;
    		var q1 = document.forms[0].spend.options[q1Ind].value;
    		var message = "How much do you spend on long distance each month? " + q1;
    		if(q1=="none"){
    			alert('Please select a value');
    			return false;
    			}
    		dispWin = window.open('','Confirm_Survey_Results','toolbar=no,status=no,width=600,height=400');
    		dispWin.document.write(message);
    		dispWin.document.write(" my message");
    		dispWin.document.close();
    	}
    
    	//-->
    </script>
    </head>
    
    <body>
    	<form onsubmit="return submitForm()" action="#" method="post">
    	<div class="question">
    		How much do you spend on long distance each month?
    	</div>
    	<div class="answer">
    		<select name="spend">
    			<option value="none" selected="selected">Select one...</option>
    			<option value="$10 or less">$10 or less</option>
    			<option value="$11 - $20">$11 - $20</option>
    			<option value="$21 - $30">$21 - $30</option>
    			<option value="$31 or more">$31 or more</option>
    		</select>
    	</div>
    	<div class="question">
    		Do you make mostly daytime or evening/weekend calls?
    	</div>
    	<div class="answer">
    		<select name="when">
    			<option value="" selected="selected">Select one...</option>
    	 		<option value="day">Day Calls</option>
    	 		<option value="evening">Evening/Weekend Calls</option>
    	 	</select>
    	</div>
    	<div class="question">
    		Please make any other comments you feel would be helpful in the space provided.
    	</div>
    	<div class="answer">
    		<textarea name="comments" cols="40" rows="6"></textarea>
    	</div>
    	<div class="processForm">
    		<input name="submit" type="submit" value="Submit" />
    		<input name="reset" type="reset" value="Reset" />
    	</div>
    	</form>
    </body>
    </html>
    I added in some checking to see whether or not the option you are trying to access was changed or not.
    Last edited by _Aerospace_Eng_; 10-17-2005 at 06:53 AM.

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for helping me out. The code you provided is working better for sure. One additional question, when I run the code now, the window pops up, my message is displayed, however, the status bar seems to indicate that the page is 'loading' continuously.

    You can check it at www.detailsfree.com/cscd378/survey.html for reference.

    David

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yeah I edited my post while you were posting. I added one line after the document.writes.

  • #5
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that was it. Got it working. Now to finish this little school project. At least I can move to the next step now.

    David


  •  

    Posting Permissions

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