...

View Full Version : Trouble writing to new window I'm creating with javascript, need help!



davenet
10-17-2005, 05:20 AM
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.



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

_Aerospace_Eng_
10-17-2005, 05:46 AM
<!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.

davenet
10-17-2005, 05:56 AM
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

_Aerospace_Eng_
10-17-2005, 06:01 AM
Yeah I edited my post while you were posting. I added one line after the document.writes.

davenet
10-17-2005, 06:09 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum