Forum Moderators: coopster

Message Too Old, No Replies

Javascript popup in php form

         

sdnative

7:22 am on Dec 4, 2009 (gmt 0)

10+ Year Member



Okay, 1 more for you...

I created a form that is inside my php code so that It will pull information and email it upon request.

On my other form I used simple java to have a window pop-up to confirm the request was entered, but I get an error when i try to add the java to my form-

echo "<form method=\"get\" name=\"subscription\" action=\"../Mail.php\">";

here is what i have with plain HTML:

<form method="get" name="subscription" action="javascript:poptastic('../Mail.php');">

I'm sure it something simple...

sdnative

7:29 am on Dec 4, 2009 (gmt 0)

10+ Year Member



Never mind.. i got it. I need to get away from this computer and get some sleep!

lol

rocknbil

9:35 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, when you wake up, some recommendations . . .

<form method="get" name="subscription" action="javascript:poptastic('../Mail.php');">

Javascript is not a URL. Javascript is not a URL. Javascript is not a URL.

And if JS is disabled, your form is now is broken. You want to do two things here:

In "poptastic" add return false to the very end of the routine. Change your form action like so:

<form method="get" name="subscription" action="/Mail.php" onSubmit="return poptastic('/Mail.php');">

function poptastic(url) {
// whatever it does, then
return false;
}

What this does is passes the submit to poptastic() without submitting the form. It's the return false that does this for you. If JS is disabled, the form will still submit. Best of both worlds.

Another thing, don't get in this habit: ../Mail.php

One day you will find yourself doing this

../../../../Mail.php

Always use a leading slash. /Mail.php. This means "start at document root" and will work in various conditions. If you ever mess with mod_rewrite, sometimes "this URL" is not really "where you are" and this will save you.

sdnative

9:52 pm on Dec 4, 2009 (gmt 0)

10+ Year Member



Yeah... I have the great please of fixing and cleaning up other mess.

thanks, that is good advice!