Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9475 > unrolled thread

How to make a multiline alert?

Started byTed Byers <r.ted.byers@gmail.com>
First post2011-12-20 15:09 -0800
Last post2011-12-21 00:44 +0100
Articles 4 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  How to make a multiline alert? Ted Byers <r.ted.byers@gmail.com> - 2011-12-20 15:09 -0800
    Re: How to make a multiline alert? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-21 01:42 +0200
    Re: How to make a multiline alert? Gene Wirchenko <genew@ocis.net> - 2011-12-20 15:43 -0800
    Re: How to make a multiline alert? Jake Jarvis <pig_in_shoes@yahoo.com> - 2011-12-21 00:44 +0100

#9475 — How to make a multiline alert?

FromTed Byers <r.ted.byers@gmail.com>
Date2011-12-20 15:09 -0800
SubjectHow to make a multiline alert?
Message-ID<c23c39d1-60f1-4155-a08f-df89e4cd36e8@g41g2000yqa.googlegroups.com>
Here is the beginning of the function:
  print "function validateFormData(vtf2) {
           var x = vtf2.ccn.value
           var msg = \"\";
           var newline = \'CR\';
           if (x==null || x==\"\") {
             vtf2.ccn.bgColor=\"lightred\";
             msg.concat(\"\\r\\n\",\"Credit card number must be
provided\");
           }
           if (!isNumber(x)) {
             msg.concat(\"\\r\\n\",\"Credit card number must be a
number\");
           }
           x = vtf2.ccexp.value
           if (x==null || x==\"\") {
             msg.concat(\"\\r\\n\",\"Credit card expiry date must be
provided\");
             alert(msg);
             return false;
           }

I managed to get this function to be executed, but it only displays
the first "Credit card number must be provided", but not the second
"Credit card expiry date must be provided'.  The concatenation looks
like it is working, at least the first time.  But what can be the
problem.  Is there a limit t the number of times concat can be called
on a string, or is alert limited in terms of the number of lines of
text it can display?

Any insights that can be provided would be appreciated.

Thanks

Ted

[toc] | [next] | [standalone]


#9476

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2011-12-21 01:42 +0200
Message-ID<jcr6gg$iaj$1@dont-email.me>
In reply to#9475
2011-12-21 1:09, Ted Byers wrote:

> Here is the beginning of the function:
>    print "function validateFormData(vtf2) {

With all due respect (I'm a lifestyle Perlert my self), please note that 
this is a JavaScript group and people here should not be expected to 
know languages like Perl or to be willing to run a Perl interpreter just 
to see the actual JavaScript code generated. Moreover, newsreaders tend 
to break lines and other things.

So please post the generated JavaScript code or, much more preferably, 
the URL of a page that demonstrates the problem in context.

>               msg.concat(\"\\r\\n\",\"Credit card number must be
> provided\");

The invocation msg.concat(...) returns a concatenated string (consisting 
of the value of msg and the argument values). It does not change the 
value of msg, as the above seems to assume.

> I managed to get this function to be executed, but it only displays
> the first "Credit card number must be provided",

That's strange, because it seems that in your code, the value of msg is 
initialized to the empty string and not changed then at all.

To modify the current value of msg by appending the values of a and b to 
it, you could use

msg = msg.concat(a, b)

though I guess people mostly use just

msg += a + b

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#9477

FromGene Wirchenko <genew@ocis.net>
Date2011-12-20 15:43 -0800
Message-ID<9272f71r5aag4p4ph0qhhu6ehennn0et15@4ax.com>
In reply to#9475
On Tue, 20 Dec 2011 15:09:06 -0800 (PST), Ted Byers
<r.ted.byers@gmail.com> wrote:

[snip]

>Any insights that can be provided would be appreciated.

          alert("Hello\nworld!");
works for me.

     I think you can remove the "\r"s.

     You might have an error in your escaping, but it is hard to tell.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#9478

FromJake Jarvis <pig_in_shoes@yahoo.com>
Date2011-12-21 00:44 +0100
Message-ID<9lckvcF16aU1@mid.uni-berlin.de>
In reply to#9475
On 21.12.2011 00:09, Ted Byers wrote:
> Here is the beginning of the function:
>    print "function validateFormData(vtf2) {
>             var x = vtf2.ccn.value
>             var msg = \"\";
>             var newline = \'CR\';
>             if (x==null || x==\"\") {
>               vtf2.ccn.bgColor=\"lightred\";
>               msg.concat(\"\\r\\n\",\"Credit card number must be
> provided\");
>             }
>             if (!isNumber(x)) {
>               msg.concat(\"\\r\\n\",\"Credit card number must be a
> number\");
>             }
>             x = vtf2.ccexp.value
>             if (x==null || x==\"\") {
>               msg.concat(\"\\r\\n\",\"Credit card expiry date must be
> provided\");
>               alert(msg);
>               return false;
>             }
>
> I managed to get this function to be executed, but it only displays
> the first "Credit card number must be provided", but not the second

Please post just the (complete) output source code.

> "Credit card expiry date must be provided'.  The concatenation looks
> like it is working, at least the first time.  But what can be the

That is impossible for the (incomplete) piece of code you posted, the 
'concat' method returns a new string and you never assign again to 'msg'.

> problem.  Is there a limit t the number of times concat can be called
> on a string, or is alert limited in terms of the number of lines of
> text it can display?
>
> Any insights that can be provided would be appreciated.
>

-- 
Jake Jarvis

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web