Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with document write, and other stuff

Status
Not open for further replies.

grayliner

Programmer
Feb 2, 2002
10
0
0
US
ok so i've been working on this for a while and i'm completely confused by this, so whoever is kind enough to help out please tell me what your doing.
what the code should do is, when you click the 'prompt' button and prompt window pops up (and it does) then you enter your name, and it writes it to a dynamic webpage. thats the part i can't get to work.

also in the window the appears after you click ok, it will add the date, does anyone know how to turn the computer numbers to match the array i have set up for days?

heres the code
<html>
<head>
<script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>
<!-- Hide from older browsers.
//JavaScript code goes here.
alert(&quot;Display a message.&quot;)
//Stop hiding from old browsers. -->


var months = new Array(12)
months[0] = &quot;Jan.&quot;
months[1] = &quot;Feb.&quot;
months[2] = &quot;Mar.&quot;
months[3] = &quot;Apr.&quot;
months[4] = &quot;May&quot;
months[5] = &quot;Jun.&quot;
months[6] = &quot;Jul.&quot;
months[7] = &quot;Aug.&quot;
months[8] = &quot;Sep.&quot;
months[9] = &quot;Oct.&quot;
months[10] = &quot;Nov.&quot;
months[11] = &quot;Dec.&quot;

var days = new Array(7)
days[0] = &quot;Sunday&quot;
days[1] = &quot;Monday&quot;
days[2] = &quot;Tuesday&quot;
days[3] = &quot;Wednesday&quot;
days[4] = &quot;Thursday&quot;
days[5] = &quot;Friday&quot;
days[6] = &quot;Saturday&quot;

var seasons = new Array(4)
seasons[0] = &quot;Fall&quot;
seasons[1] = &quot;Winter&quot;
seasons[2] = &quot;Spring&quot;
seasons[3] = &quot;Summer&quot;

var browser = navigator.appName
var version = navigator.appVersion

function promptwindow() {
var promptwin = prompt(&quot;What is your name?&quot;,&quot;&quot;)

var newWindow
function makeNewWindow() {
newWindow=window.open(&quot;&quot;,&quot;&quot;,&quot;status,height=200,width=300&quot;)


function drawPage(useName) {
var newWind = window.open(&quot;&quot;,&quot;dynCreate&quot;,&quot;height=200,width=300&quot;)
var thePage = &quot;&quot;
thePage += &quot;<html><head><title>My New Page</title></head><body>&quot;
thePage += useName
thePage += &quot;, this page is being written dynamically.&quot;
thePage += &quot;</body></html>&quot;
newWind.document.write(thePage)
newWind.document.close()
}
}
}


</script>
<title>right</title>
<meta name=&quot;author&quot; content=&quot;David Mudder&quot; />
<link rev=&quot;made&quot; title=&quot;author's e-mail&quot; href=&quot;mailto:klay2@juno.com&quot; />
</head>

<body bgcolor=&quot;#33CC00&quot; text=&quot;#000000&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
Name:
<input type=&quot;text&quot; name=&quot;textfield&quot; />
<br />
Address:
<input type=&quot;text&quot; name=&quot;textfield2&quot; />

<br />
E-mail:
<input type=&quot;text&quot; name=&quot;textfield3&quot; />
<br />
Male:
<input type=&quot;radio&quot; name=&quot;radiobutton&quot; value=&quot;radiobutton&quot; checked />
<br />
Female:
<input type=&quot;radio&quot; name=&quot;radiobutton&quot; value=&quot;radiobutton&quot; />
<br />
Unsure:
<input type=&quot;radio&quot; name=&quot;radiobutton&quot; value=&quot;radiobutton&quot; />

<p>Free Magazine:
<input type=&quot;checkbox&quot; name=&quot;checkbox2&quot; value=&quot;checkbox&quot; />
<br />
Free Book:
<input type=&quot;checkbox&quot; name=&quot;checkbox3&quot; value=&quot;checkbox&quot; />
<br />
Free Pamphlet:
<input type=&quot;checkbox&quot; name=&quot;checkbox&quot; value=&quot;checkbox&quot; />
</p>

<input type=&quot;button&quot; name=&quot;button1&quot; value=&quot;Prompt&quot; onClick=&quot;promptwindow()&quot; />
<input type=&quot;button&quot; name=&quot;button2&quot; value=&quot;button2&quot; />
<input type=&quot;button&quot; name=&quot;button3&quot; value=&quot;button3&quot; />
<br />
<br />
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; />
</form>
</body>
</html>
 
About the Prompt issue, here's how to do it:

function promptwindow() {

var promptwin = prompt(&quot;What is your name?&quot;,&quot;&quot;);

newWindow=window.open(&quot;&quot;,&quot;&quot;,&quot;status,height=200,width=300&quot;);
newWindow.document.open();
newWindow.document.write('<html><body>');
newWindow.document.write(promptwin);
newWindow.document.write('</body></html>');
newWindow.document.close();

}


I didn't understand your 2nd question.
 
not so much that as how do i put more variables into the new browser window. like in the one the pops up after the name the person enters i want it to show the browser name, and the version. where do i insert this?
 
also how does one set up the prompt part so that if no data is entered it say &quot;no data&quot; where the name should be?
 
you could do this for the prompt box:
Code:
var blah = prompt (&quot;Question Here&quot;,&quot;No Data&quot;);
// then for even more security you could do:
if (blah == &quot;undefined&quot;)
var blah = &quot;No Data&quot;;
else
return true;
The pen is mightier than the sword.
 
OK, here it is:

function promptwindow() {

var promptwin = prompt(&quot;What is your name?&quot;,&quot;&quot;);

if ( (promptwin == null) || (promptwin == &quot;&quot;) )
promptwin = &quot;NO DATA&quot;

newWindow=window.open(&quot;&quot;,&quot;&quot;,&quot;status,height=200,width=300&quot;);
newWindow.document.open();
newWindow.document.write('<html><body>');
newWindow.document.write(promptwin);
newWindow.document.write('<br><strong>navigator.userAgent:</strong> ', navigator.userAgent);
newWindow.document.write('</body></html>');
newWindow.document.close();
}

You can add any html code using newWindow.document.write(), as in my example with navigator.userAgent. Just remember to place it inside quotes &quot; &quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top