HTML Goodies: Script Tip: Week 51

By Joe Burns


51-derful Tips...

Let's wrap this puppy up. We've gotten all the buttons to work but one. This is it.

Here's the script and its effect once again.


See it in Action

Here's the Code

(It's big. Get it all.)


The button that displays the frame code in a new window looks like this:

<INPUT onClick=view()
type=button value=" View It! ">

The function view()looks like this:

function view()

{
if (document.Framer.Pastebox.value=="")
{ alert ('The paste box is empty.')
return false;
}

else
{ alert('If you like the results, paste it to a text editor!')
boat = open ("","DisplayWindow")
see = parent.document.Framer.Pastebox.value
boat.document.write (see)
return true;
}
}

The function is again set up as an If/Else conditional statement. The purpose is to post an alert box if the user attempts to view when nothing is there to view:

if (document.Framer.Pastebox.value=="")
{ alert ('The paste box is empty.')
return false;
}

If the bottom TEXTAREA box is empty (""), the alert goes up and the return is false. That means the script dies right there. It doesn't go any further.

Otherwise:

else
{ alert('If you like the results, paste it to a text editor!')
boat = open ("","DisplayWindow")
see = parent.document.Framer.Pastebox.value
boat.document.write (see)
return true;


      Assign the code open("","DisplayWindow") to the variable "boat". Why boat? I don't know. Ask the author. Notice the empty quotes at the beginning. That is where a page URL would normally sit. Since it's empty, it's forcing the script to look at itself for the information to display.

Next, the variable "see" is assigned the value of what is in the bottom TEXTAREA box (parent.document.Framer.Pastebox.value). Now the command "parent" sits in front because we're dealing with two windows and we want the information taken from the window that spawned the new one... the parent.

Into "boat" (the new window), document.write "see", the contents of the bottom TEXTAREA box found on the parent window. Return true. Complete the event.

There you go. I'll bet the first time you saw this one you thought it was going to take 10 tips to complete. That's part of the beauty of JavaScript programming. You can use the same format again and again in the same script to get different results. I only had to show you one frame code function and you could get them all.

Next week we'll start a new one. I've always enjoyed the math side of JavaScript. Let's do a calculator.



Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
  •  
  •  
  •  
Thanks for your registration, follow us on our social networks to keep up-to-date