|
Posted by Colin McKinnon on 09/26/43 11:29
bonehead wrote:
>
> I've been trying, with limited success, to produce a javascript alert
> box which shows the user a validation error message. The error message
> itself is dynamic, i.e., it's contained within a php variable.
>
> I seem to be running into two issues:
>
> 1. I can raise the alert box, but I can't pass the string contained in
> the $myerrormessage variable. Clearly I don't quite have the syntax just
> right.
>
Bearing in mind that you may be getting OT....
What javascript error are you getting? What does the HTML from your script
say (just the bit around the alert()). You seem to be using Firefox - take
a look at the javascript console - or better yet install Venkman.
> 2. When the alert box does appear, the content of the web page behind
> the alert box disappears, i.e., the page goes blank. When the user
> clicks the OK button on the alert box, the blank web page remains, and
> the user must click the Back button to return to the form.
>
erm...because they had to submit the page to get the PHP to run, and your
PHP didn't write a new page...or the PHP died trying to execute your
code....or you found one of the many bugs in internet explorer which
produce this kind of behaviour.
> The html that generates the form is wrapped inside a php function (the
> file itself is php). The 'action' attribute of the form is "<?php echo
> $PHP_SELF ?>". The form also contains a hidden field called 'action'
> whose value is 'send_mail'.
>
> When the user clicks the submit button, the script calls itself
> recursively,
I sincerely hope you don't really mean that.
> and the $action variable's value, 'send_mail', is sent to a
> switch. The switch calls a send_mail function, which performs all the
> validation checks and generates an html error message if $myerrormessage
> is not empty. This script was based on models provided in this book:
>
> http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764557440.html
>
> Currently I'm rendering the error message via another php function which
> produces the html containing $myerrormessage. This works just fine, of
> course, but I'm afraid some wiseguy web developer out there will look at
> it and proceed to tell me all about how lame it is.
>
> Can I add an onclick attribute to the form,
No - forms don't have an onclick method. Buttons and other things do though.
> to call a javascript
> function inside the <body> tag of the html which renders the form?
So you want the function to generate the form - the form which didn't
previously exist - when you click on it.
> Does
> anyone have an example of what I'm looking for?
No I've given up the psychotropics.
C.
Navigation:
[Reply to this message]
|