473,657 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript alert question

Greetings,

I'm working on an e-mail form (btw many thanks to Philip Ronan for the
very cool email address format tester function, best I've seen so far).

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.

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.

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, 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/WroxTit...764557440.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, to call a javascript
function inside the <body> tag of the html which renders the form? Does
anyone have an example of what I'm looking for?
Oct 17 '05 #1
6 3132
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/WroxTit...764557440.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.
Oct 17 '05 #2
Colin McKinnon wrote:
Does
anyone have an example of what I'm looking for?


No I've given up the psychotropics.


Okay, fine, just show me whatever you consider to be a good example of a
php e-mail web form with validation and error handling. That's all I'm
really looking for. It doesn't have to have any javascript in it at all.

Meanwhile I'll send a message to the authors of the book I cited telling
them that you'll shortly be explaining exactly what's wrong with using
$PHP_SELF as the action argument of a form, and providing a much better
example.
Oct 17 '05 #3
bonehead (se**********@h ere.net) wrote:
: Colin McKinnon wrote:
: >>Does
: >>anyone have an example of what I'm looking for?
: >
: > No I've given up the psychotropics.

: Okay, fine, just show me whatever you consider to be a good example of a
: php e-mail web form with validation and error handling. That's all I'm
: really looking for. It doesn't have to have any javascript in it at all.

Hum, if that's what you want then why didn't you just say so.

PhpBB seems to handle sending mail just fine, perhaps that application
could provide suitable examples for you of getting and using email
addresses.

There are also loads of html and cgi books that discuss validating form
input.

There have been lots of threads here (i.e. googling time) about what sort
of validation is needed by am "email form". Key item is that the email
addresses must be controlled serverside by the php script during the
invocation when it actually sends the mail. (I.e. hidden fields in forms,
or javascript validation of email addresses is useless.)
: Meanwhile I'll send a message to the authors of the book I cited telling
: them that you'll shortly be explaining exactly what's wrong with using
: $PHP_SELF as the action argument of a form, and providing a much better
: example.

Hum, I didn't notice him saying he was going to do any such thing. Are
you trying to be sarcastic? If so, I'm afraid you put your foot in your
mouth since what he questioned was your claim of "recursive" calls using
that variable. I think it highly doubtful the wrox example recursively
calls itself, which is not at all the same thing as using it as the action
of a form - though from your verbose, technically loose description, I am
not sure you would quite understand that (yet).

Oct 17 '05 #4
On 17/10/2005 21:49, Colin McKinnon wrote:
bonehead wrote:


[snip]
Can I add an onclick attribute to the form,


No - forms don't have an onclick method. Buttons and other things do
though.


Incorrect. FORM elements do dispatch click events and fire click
listeners. In fact, most elements do.

Search a DTD for occurrences of the %events; parameter entity reference
(including any other entities, like %attr;, that use it). You'll find
that it comes up quite frequently.

The %events; parameter entity definition also defines other event types,
including those for mouse and keyboard interaction. The remaining types
- blur, change, load, submit etc. - are limited to certain specific
elements.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 17 '05 #5
On Mon, 17 Oct 2005 10:21:27 -0700, bonehead <se**********@h ere.net>
wrote:
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.
You have to output your error messages as proper Javascript code; this
might involve escaping various characters that have meaning in
Javascript or HTML.
2. When the alert box does appear, the content of the web page behind
the alert box disappears, i.e., the page goes blank.
This can happen depending on how your javascript is being called. If
you have something like this:

<a href="javascrpt :callSomeFuncti on();">Click Me</a>

Then this will cause the browser to redirect to a blank page.
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.
It doesn't sound too bad.
Can I add an onclick attribute to the form, to call a javascript
function inside the <body> tag of the html which renders the form? Does
anyone have an example of what I'm looking for?


Try hooking into the onsubmit event of the form. You can return false
to cancel the submit or return true to allow it. In that function,
you can you validation and show any alert boxes.

Later,

Oct 18 '05 #6
I'd take a look at PEAR's QuickForm
it would be something like this:

<?php
require_once('H TML/QuickForm.php') ;

$form = new HTML_QuickForm( 'emailform', 'POST');

$form->addElement('te xt', 'email', 'Whats your email?');

$form->addRule('email ', 'Please, type your email', 'required');

//not completely sure about this one
$form->addRule('email ', 'Please, type your REAL email', 'regex',
'/[^@]+@.*/');

if($form->validate()){
$form->freeze();
$form->process('proce ssf', false);
}
else{
$form->display();
}
?>

You must also provide de processf function;

function processf($value s){
//this will show you the form values
print_r($values );
}

Oct 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3340
by: Matt | last post by:
Is it possible to put XSL instructions inside JavaScript? For example, pop up a message box with the xml value: alert(value in xml); Approach #1: <script type="text/javascript"> alert(<xsl:value-of select="@id"/>); </script> It will have javascript errors
14
5453
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
15
4213
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is avaliable at... http://www.geocities.com/binnyva/code/javascript/advanced_tutorial/ If any of you could spare the time, please have a look at my tutorial
12
1402
by: Joe | last post by:
Hello All: I'm sure that one of you can quickly spot the error in my script. I am using a small javascript function to retrieve the text of a hyperlink in a datagrid column. Here is my script: function parseHyperlinkId(o) { alert(o.text);
13
3017
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php and the put the data into an array in the post.... anywhat. I have a link <a href="javascript:change_class()" >Block mode</a> to
6
2523
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you get response from a Confirm() popup window to uncheck all server-side checkboxes placed in a panle of a web user control? I am using ASP.Net 2.0, Thanks. Need info...
14
2294
by: maidane | last post by:
Hi, I got the following situation using the AC_Quicktime library. Apple recommend to use a Javascript call to generate the OBJECT tag (http://developer.apple.com/internet/ieembedprep.html). I am storing String entries representing the innerHTML of a div that I will update at runtime. As a result, some of these string entries are actually loooking like: <script language="JavaScript" type="text/javascript">
1
1239
by: Morten Snedker | last post by:
If my question is off this group, please point me in the right direction. Here goes: My scipt fails between alert-2 and alert-3 with "Object doesn't support this property or method" (freely translated from Danish).
16
1905
by: Tony Girgenti | last post by:
Hello. I just finished reading two articles about javascript here: http://msdn2.microsoft.com/en-us/library/bb332123(VS.80).aspx I tried some javascript testing in VS2005, SP1, VB , .NET 2.0, ASP.NET 2.0 on WIN XP Pro, SP2. It's real simple. I put a button on a page and coded the onClick in it like this:
4
68192
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!!
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.