Thank you very much for the helpful script advice. Is this cross browser compatible? And will it work if called as an alert to multiple fields for form validation?

SpaceFrog
—
2005-03-03T12:55:28Z —
#4

Tested with IE and firefox...in fact it is just a div that you toggle from visible to invisible...It can work if called from anywhere, you would only have to change message in alertboxyou could actually make a function passing the alert message as a parameter ...

cherylmmm
—
2005-03-04T02:40:35Z —
#5

Thanks very much I will give it a go over the weekend and let you know how it worked.

cherylmmm
—
2005-03-07T01:42:01Z —
#6

I tried the script and it works very well. However when I tried to get the message to change according to each form field's validation message, I am getting the error that 'msg' is undefined in the body of the page. Here is the script for the test page, with only 2 form fields for brevity. Unfortunately I don't know how to link the msg in the body to the definitions in the head. ( I also don't know how to put a code box into this message like you did, sorry)<html><head> <title>Test</title> <script type="text/javascript" language="javascript"> function validate() { //Check name field is not emptyvar oNv=document.orderform.Name.value;var msg="Please enter your name";if (oNv=='') {document.getElementById('testzone').style.display='block';event.returnValue=false;}

I don't know how those little faces got into my code, I didn't put them there on purpose.

dc_dalton
—
2005-03-07T02:19:01Z —
#8

The forum software picked up some if the code that looked like the smilies code... if you use the code button (#) above the text box you type your message into you wont have that problem... highlight the script then click the code button it will appear in the post like this:

fpo hj
g sg d
gd
g dg
dg fdg

and you dont have to worry about a smily attack!

Kravvitz
—
2005-03-07T04:43:43Z —
#9

You can only use document.write() when the page is loading.

You can use document.getElementById('testzone').innerHTML, which is not part of the W3C DOM but is supported by several browsers for cross-browser compatibility.

cherylmmm
—
2005-03-07T05:26:25Z —
#10

Thank you for that advice, where do I put this line, in the head or in the body, and how do I connect it to the message that I want to display?

Kravvitz
—
2005-03-07T06:27:26Z —
#11

event.returnValue is IE only. There is no reason to use it here anyway.

Thank you very much for your help. Unfortunately, when I tried your code, it brought all the messages up in the alert box at the same time. I tried giving the messages numbers, but that created a whole heap of other errors. I don't know enough about javascript to see what I am doing wrong.

SpaceFrog
—
2005-03-07T08:10:08Z —
#13

Nothing surprising there as you are assigning msg before testing fields ...message should be assigned in the if !!!

Yay! That works. Thank you so much. Now to add 25 other validation type of messages without messing it up again.

Cheers Cheryl

Kravvitz
—
2005-03-07T08:25:13Z —
#15

Oops, I guess I should have tested it by actually putting text in the fields.

Yet more proof that I'm great at making silly mistakes.

Anyway, you're welcome, I'm glad I could help.

cherylmmm
—
2005-03-07T08:29:31Z —
#16

Whoops I spoke too soon. It doesn't work in firefox for me on XP, only in IE. Is the innerHTML tag just a proprietary one? If so, I don't think I will be allowed to use it.

Here's my brief. I have to have all these form field validations and the warning message must be written in red text. It has to be crossbrowser compliant in later browsers and the code must validate according to standards. I have the form validation working perfectly in IE 6, firefox and netscape but I have used alert box messages and after all my effort, I then found I couldn't make the text red. That is where I came in here. Does anyone have any idea on a solution?

SpaceFrog
—
2005-03-07T08:30:37Z —
#17

I would us a switch that would make your code more leagible...hold on a sec I'll be right back with an example ...

hul well the switch would only allow you to make one correction at a time this means if there are three empty fields it would show one alert box at each validation...

In a sense, innerHTML is IE propritary, however, even though it is not part of any W3C standard Opera 7+, Netscape 6+, and Mozilla/Firefox support it.

cherylmmm
—
2005-03-07T11:39:31Z —
#19

I am still not getting this to work in firefox. I would like to show all the code I am using, but the smilies get in the way and I cannot find the place where it says to 'add code'. I have tried the quick reply and the advanced reply and neither give me the option to 'add code'. What am I doing wrong?

Kravvitz
—
2005-03-07T22:31:35Z —
#20

You see the "#" image in advanced reply?

Copy and paste your text into the textarea select it and then click that image.