Wells-it.com - Web Hosting

Basic Javascript

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 330 posts

Joined: Apr 2000

What's wrong with the following code? Header is a text box...

<?php
&lt;script language="javascript\"&gt;

function isFilledHeader()
{
if(document.AddForm.Header.Header == \"\");
    {
    alert('You must complete the Header field');
    return false
    }
}
&lt;/script&gt;
?>

When I try to run it it always returns false and generates the error. What am I doing wrong here?

Thanks for your help.

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Just a guess, but try changing:

document.AddForm.Header.Header

to

document.AddForm.Header.value

If that doesn't work post back with the form/text box code also. Smiling

They have: 330 posts

Joined: Apr 2000

I rewrote it here before which is why that was not correct. I had that correct in my app.

<?php
&lt;script language="javascript\"&gt;

function isFilledHeader()
{
if(document.AddForm.Header.value == \"\");
    {
    alert('You must complete the Header field');
    return false
    }
}
&lt;/script&gt;

</head>
...
<form action=\"AddInformation1.asp?Subcategory=<%= Request.QueryString(\"Subcategory\")
?>

\" method=\"post\" name=\"AddForm\" onSubmit=\"return isFilledHeader()\">

Web Training

Header

?>

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Oh, wait, I missed this before. Take the semicolon off of this line:

if(document.AddForm.Header.value == "");

It doesn't need it since it is introducing a conditional. Smiling

They have: 330 posts

Joined: Apr 2000

Perfect, thank you.