This site requires JavaScript, please enable it in your browser!
Greenfoot back
Duta
Duta wrote ...

2012/2/24

HTML (not to do with Greenfoot)

Duta Duta

2012/2/24

#
I'm not sure how many people in here will be strong in html, but I figured I'd post this question here anyway. So I've done a little experimenting in html - having not touched it in years, and even then I barely knew what to do with it, and now I'm trying to work out how to access a text field's data... this code should (in my mind) make a popup with a title of the first text box and some text in it from the second text box. I know the pop-up works as I tried it first by changing <a onclick="return popup(text1, text2)">Popup</a> to <a onclick="return popup('A title', 'Some text')">Popup</a>, however now I'm trying to access some user-entered data, I can't work it out :/. Oh and I don't think I need the <form></form> tags but I put them there in case it made a difference - I'm not 100% what they do. Here's my (non-working, guesswork) code: <html> <title>HTML Page 1</title> <script type = "text/javascript"> <!-- function popup(title, text) { newwindow2=window.open('','name','height=200,width=150'); var tmp = newwindow2.document; tmp.write('<html><head><title>' + title + '</title>'); tmp.write('<link rel="stylesheet" href="js.css">'); tmp.write('</head><body><p>' + text + '</p>'); tmp.write('<p><a href="javascript:self.close()">Close</a> this popup.</p>'); tmp.write('</body></html>'); tmp.close(); } // --> </script> <body> <form> Text field 1: <a name="text1"><input type="text" size="15" maxlength="15" /></a> <br> Text field 2: <a name="text2"><input type="text" size="15" maxlength="15" /></a> <br> <a onclick="return popup(text1, text2)">Popup</a> (Text field 1, Text field 2) </form> </body> </html>
Duta Duta

2012/2/24

#
So I changed the <a onclick ...> line to <a onclick="return popup(self.text1, self.text2)">Popup</a> (Text field 1, Text field 2) and now when I click "Popup" the popup comes up with the title and text as "undefined". Will experiment more tomorrow
Duta Duta

2012/2/25

#
Incase anyone's interested, I got it working with the following code: <html> <title>HTML Page 1</title> <script type = "text/javascript"> <!-- function popup() { newwindow2=window.open('','name','height=200,width=150'); var title = document.forms.value; var text = document.forms.value; var tmp = newwindow2.document; tmp.write('<html><head><title>' + title + '</title>'); tmp.write('<link rel="stylesheet" href="js.css">'); tmp.write('</head><body><p>' + text + '</p>'); tmp.write('<p><a href="javascript:self.close()">Close</a> this popup.</p>'); tmp.write('</body></html>'); tmp.close(); } // --> </script> <body> <form> Text field 1: <input name="text1" type="text" size="15" maxlength="15" /> <br> Text field 2: <input name="text2" type="text" size="15" maxlength="15" /> <br> <a onclick="return popup()">Popup</a> (Text field 1, Text field 2) </form> </body> </html>
You need to login to post a reply.