Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox tied to textarea problems

Status
Not open for further replies.

struth

Programmer
Aug 26, 2001
114
GB
Can't seem to get this to work:

On submission I want check if a textarea has had content added. If it has users must also have checked a 'read more' checkbox.

The workings of the function as I have them at the moment are:

var moreNews
moreNews=Form1.News.value

if (moreNews!=""&& Form1.readmore.checked==false)
{
alert("Please check 'read more link'");
return ;
}

Many thansk for any help



"Away from the actual ... everything is virtual"
 
well the only problem i see is that:
if (moreNews!="" && Form1.readmore.checked==false)
ther must be a space before &&.


Known is handfull, Unknown is worldfull
 
struth, I think the problem lies in parenthesis, as in you don't have them. I experience this type of problem so I add in parenthesis and it works for me.
Try this:
Code:
  var moreNews
  moreNews=Form1.News.value 
        
  if ((moreNews!=" ") && (Form1.readmore.checked==false)) {
    alert("Please check 'read more link'");
    return ;
  }

I added a pair of parenthesis around both statments.

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage.
It's no big deal really...
 
GUJUm0deL i dont think that is the problem. even without the bracket it will work...

Known is handfull, Unknown is worldfull
 
And it has worked for me......

Thanks GUJUm0deL, I'll remember the tip.

"Away from the actual ... everything is virtual"
 
ahh!! proved wrong but can anyone tell me why?

Known is handfull, Unknown is worldfull
 
Can't say vbkris, the '&&' error you mentioned was one I added in typing it in (I sometimes do this rather than cut'n'paste in the hope that I can spot my own error ... but in this case I added one in).

But I can't see how the addition of these parentheses effects how the expressions are evaluated. I did cut'n'paste from GUJUm0deL's example so maybe this overcame another error in my code ... but I can't be sure.

Well if anyone else can shed some light on this, I too would be interested to know.





"Away from the actual ... everything is virtual"
 
The reason the parenthesis works is that you're calling two statements at the same time. As in, if one and two are satisfied then do something, JS needs the parenthesis to distinguish one statement from the other. At least that's how I see it...
Glad the code helped ya...

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage.
It's no big deal really...
 
well if thats the problem then half my applications shouldnt work...

and i just notcied one thing now:
guju seems to have changed ur if condition from:
moreNews!=""
to
moreNews!=" "


that makes one hell of a change in JS.

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top