Click to See Complete Forum and Search --> : help please


kate22
05-07-2003, 12:06 PM
Ok I have to make a page in which you enter a URL and then you click check boxes such as
toolbars,location, directories, statues, etc. Only the ones that are checked are to appear
on teh pop up page..then i have 2 text boxes for width and height..then an enter and reset
button..how would i code this? i am really new to javascript so any help is great

pyro
05-07-2003, 01:03 PM
Try something like this out. You should be able to edit it to be as you wish...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Popup Maker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">

function createPopup(frm) {

var x = "0";
var msg = "Please insert a value for: \n\n";
if (frm.page.value == "") {
msg += "URL\n";
x = 1;
}
if (frm.width.value == "") {
msg += "Width\n";
x = 1;
}
if (frm.height.value == "") {
msg += "Height\n";
x = 1;
}
if (frm.top.value == "") {
msg += "Top\n";
x = 1;
}
if (frm.left.value == "") {
msg += "Left\n";
x = 1;
}

var props = "";
props += "width="+frm.width.value+",";
props += "height="+frm.height.value+",";
props += "top="+frm.top.value+",";
props += "left="+frm.left.value+",";
if (frm.toolbar.checked == true) {
props += "toolbar=1,";
}
if (frm.resizable.checked == true) {
props += "resizable=1,";
}
if (frm.location.checked == true) {
props += "location=1,";
}
if (frm.directories.checked == true) {
props += "directories=1,";
}
if (frm.status.checked == true) {
props += "status=1,";
}
if (frm.menubar.checked == true) {
props += "menubar=1,";
}
if (frm.copyhistory.checked == true) {
props += "copyhistory=1,";
}

if (x == 1) {
alert (msg);
}
else {
window.open(frm.page.value,frm.page.name,props);
}

return false;
}

</script>

</head>

<body>
<form method="post" onsubmit="return createPopup(this);">
Popup URL: <input type="text" name="page"><br/>
Popup Window Name: <input type="text" name="name"><br/>
Width: <input type="text" name="width"><br/>
Height: <input type="text" name="height"><br/>
Top: <input type="text" name="top"><br/>
Left: <input type="text" name="left"><br/>
Toolbar: <input type="checkbox" name="toolbar"><br/>
Resizable: <input type="checkbox" name="resizable"><br/>
Location: <input type="checkbox" name="location"><br/>
Directories: <input type="checkbox" name="directories"><br/>
Status Bar: <input type="checkbox" name="status"><br/>
Menu Bar: <input type="checkbox" name="menubar"><br/>
Copy History: <input type="checkbox" name="copyhistory"><br/>
<input name="submit" type="submit" value="Submit">
</form>
</body>
</html>

kate22
05-07-2003, 01:30 PM
I tried that. how do i make whatever link is typed in a pop up window. also if say the toolbar selection is not selected then the pop up window would not have it

pyro
05-07-2003, 01:35 PM
Did you even try my code? It does all that....

kate22
05-07-2003, 01:44 PM
ok sorry about that..i accidently didnt copy one line of the code & it screwed up that one part of it. now if i want to elminate the top and left can i do that? thanks alot..i also need to add a reset button in which to clear the text boxes adn the check boxes out

goofball
05-07-2003, 02:12 PM
You should get a book on JavaScript or basic HTML.

Check out this site:

http://htmlgoodies.earthweb.com/

It's got a lot of answers to all kinds of basic questions like these.

pyro
05-07-2003, 02:20 PM
Yes, try editing the code yourself and then we can help you if you get stuck. It should be quite easy, now that I gave you all the above code...

kate22
05-07-2003, 02:44 PM
i edited the page with the objects i need and so forth. Can i set a default value of the top and left?this seems to be why i cannot see thep age when it pops up.

pyro
05-07-2003, 10:25 PM
To set a default top and left, take this part of my code:

props += "top="+frm.top.value+",";
props += "left="+frm.left.value+",";

and chage to:

props += "top=200,";
props += "left=200,";

kate22
05-07-2003, 11:16 PM
OK heres the code after I modified it and moved around somethings and took out a few options and added others:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Windows Creation Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">

function createPopup(frm) {

var x = "0";
var msg = "Please insert a value for: \n\n";
if (frm.page.value == "") {
msg += "URL\n";
x = 1;
}
if (frm.width.value == "") {
msg += "Width\n";
x = 1;
}
if (frm.height.value == "") {
msg += "Height\n";
x = 1;
}
if (frm.top.value == "") {
msg += "Top\n";
x = 1;
}
if (frm.left.value == "") {
msg += "Left\n";
x = 1;
}

var props = "";
props += "width="+frm.width.value+",";
props += "height="+frm.height.value+",";
props += "top=200,";
props += "left=200,";
if (frm.toolbar.checked == true) {
props += "toolbar=1,";
}
if (frm.resizable.checked == true) {
props += "resizable=1,";
}
if (frm.location.checked == true) {
props += "location=1,";
}
if (frm.directories.checked == true) {
props += "directories=1,";
}
if (frm.status.checked == true) {
props += "status=1,";

}
if (frm.menubar.checked == true) {
props += "menubar=1,";
}
if (frm.scroll.checked == true) {
props += "scroll=1,";
}
if (x == 1) {
alert (msg);
}
else {
window.open(frm.page.value,frm.page.name,props);
}

return false;
}

</script>

</head>

<body>
<center><form method="post" onsubmit="return createPopup(this);">
<input type="text" name="page"> : URL <br/>
<input type="checkbox" name="toolbar"> : Toolbar<br/>
<input type="checkbox" name="location"> : Location<br/>
<input type="checkbox" name="directories"> : Directories<br/>
<input type="checkbox" name="status"> : Status<br/>
<input type="checkbox" name="menubar">Menubar<br/>
<input type="checkbox" name="scroll">Scrollbars<br/>
<input type="checkbox" name="resizable"> : Resizeable<br/>
Width: <input type="text" name="width"><br/>
Height: <input type="text" name="height"><br/>
<input name="submit" type="submit" value="Submit"></center>
</form>
</body>
</html>

But for some reason the pop up window isnt popping up. try this and see if it pops up for you

KeshavaR
05-08-2003, 12:13 AM
That was a neat code PYRO ! cool!

and for Reset KATE22 take this :

<input name="Reset" type="Reset" value="Reset">

Cheers !

Keshav

kate22
05-08-2003, 12:33 AM
thanks!

you wouldnt happen to know why my pop up window isnt popping up do you? the code in my last post is what i have

KeshavaR
05-08-2003, 12:57 AM
Well, Pyro's original code worked perfectly for me, and the altered code of yours did not.

Try having Window name as a parameter.

pyro
05-08-2003, 07:18 AM
kate22-

Get rid of these lines in your code and it will work fine:

if (frm.top.value == "") {
msg += "Top\n";
x = 1;
}
if (frm.left.value == "") {
msg += "Left\n";
x = 1;
}

KeshavaR-

Glad you liked the code! :D

Cheers!

kate22
05-08-2003, 09:15 AM
so I will understand this, the code that i just got rid of was that setting the top and left value as null and that was why it wasnt coming up?

pyro
05-08-2003, 09:23 AM
No, it was checking the if the form fields top and left were null, which you had deleted, so there were. If they were null, it told the script not to open the window, so this is why it wasn't working...

kate22
05-08-2003, 09:35 AM
ahh ok i see that now..
can you look at this code and see why i am gettin an error. you will of course not have a pic or sound b/c you dont have the files but you could look over the code. the pic works but i am gettin an error on LIne 6 char. 24

<HTML>
<BODY>

<SCRIPT LANGUAGE="JavaScript">
<!--
function playSound() { document.Sound.play(); }

//-->
</SCRIPT>
<BODY>
<H3>Task 2: Play a sound on demand</H3>
<P>Please click on the image below</P>
<a href="javascript:playSound()"><img src="sound.jpg" width="100" hight="100"></a><br>

<embed src="sound.au" hidden=true autostart=false loop=false name="Sound" mastersound>

</BODY>
</HTML>

pyro
05-08-2003, 09:50 AM
Try changing this line:

<embed src="sound.au" hidden=true autostart=false loop=false name="Sound" mastersound>
to this: (difference in bold)

<embed src="sound.au" hidden autostart=false loop=false name="Sound" mastersound>
;)

kate22
05-08-2003, 09:54 AM
tried..still the same error line 6 char. 24

pyro
05-08-2003, 09:59 AM
What browser were you using? It worked for me in IE6 and NN7...

kate22
05-08-2003, 10:05 AM
I am pretty sure its IE6...i have win xp pro

Jona
05-08-2003, 10:06 AM
Pyro, I do believe that earlier versions of IE do not support <embed>, and are supposed to use <object> instead. But, as V.V. and I kinda thought about, <embed> works in some versions of IE (including version 6 and probably 5.5), and also works in Netscape, even though it's not actually "supposed to" work in IE.

kate22
05-08-2003, 10:11 AM
i tried replacing the embed with object and i am still getting an error on line 6 char. 24 but this time it says error:
'document.Sound' is null or not an object

pyro
05-08-2003, 10:16 AM
Originally posted by Jona
Pyro, I do believe that earlier versions of IE do not support <embed>Nope, it works in IE since version 3, and in scripts since version 4. http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/embed.asp

Jona
05-08-2003, 10:24 AM
Hmmmm..... I see. I didn't know it was even in HTML 3.2. Wow, :p

Kate22, use document.getElementsByTagName("EMBED")[0] instead of "Sound"

kate22
05-08-2003, 10:29 AM
this?

{ document.getElementsByTagName("EMBED")[0].play(); }

Jona
05-08-2003, 10:36 AM
Yes, that should work. Or, you can give the <embed> and id attribute: <embed id="Sound"> And then, you can refer to it in many ways (most of which are IE only):

1. document.all['Sound'].play(); - IE only

2. document.getElementById("Sound").play(); (This works in Netscape);

3. document.Sound.play(); - IE only

4. document.getElementsByTagName("EMBED")[0] - The first part I showed you, works in Netscape and IE (but not NN4).