473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

promp doesn't work

Hi,
I am trying to change "print results" for promt.
I don't want the output to be in HTML, it should be alert boxes.It
should be fairly easy, but every time i am changing the - >
results.innerHTML = out; it stops working.

thanks
<head>
<body>

<input id='phrase' type='text'><br>
<input type='submit' value='Click to check for palindrome'
onClick='validate();return false;'>
<span id='results'></span>
</td>
</tr>

</table>

<script type="text/javascript" language="Javascript">
<!--

var forward;
var backward;

function validate()
{
var s = "";
forward = "";
backward = "";

var p = document.getElementById( "phrase" ).value;

if ( p == null || p.length == 0 ) {
printResults(0, "A blank string is not valid. Try entering
some text.");
}

p = p.toLowerCase();

var regex = new RegExp( /[a-z]/ );

for (i = 0; i < p.length; i++) {
if ( regex.test( p.charAt( i ) ) ) {
s += p.charAt( i );
}
}

for (i = 0; i < s.length; i++) {
forward += s.charAt( i );
backward += s.charAt( s.length - 1 - i );
}

if ( forward == backward )
{
printResults( 1 );
}
else
{
printResults( 0 );
}
}

// 1 for valid, 0 for not valid

function printResults( isValid, msg )
{
var valid = "valid palindrome.";
var not_valid = "NOT a valid palindrome.";

var results = document.getElementById( "results" );
var p = document.getElementById( "phrase" ).value;

var out = "Results";

if ( isValid ) {
out += "Yup, " + p + " is a " + valid;
}
else {
out += "Nope, " + p + " is " + not_valid;
}

out += "<br>";

if ( msg != null && msg.length 0 ) {
out += msg + "<br>";
}

if ( !isValid && forward.length 0 && backward.length 0 )
{
out += "[" + forward + "] (forward)<br>" +
"[" + backward + "] (backward)";
}

results.innerHTML = out;
}

function clearFields()
{
document.getElementById( "results" ).innerHTML = "";
var p = document.getElementById( "phrase" );

p.value = "";
p.focus();
}

clearFields();

//-->
</script>
</body>
</html>
Aug 8 '08 #1
2 1055
little susane wrote on 08 aug 2008 in comp.lang.javascript:
Hi,
I am trying to change "print results" for promt.
I don't want the output to be in HTML, it should be alert boxes.It
should be fairly easy, but every time i am changing the - >
results.innerHTML = out; it stops working.

thanks
<head>
<body>

<input id='phrase' type='text'><br>
<input type='submit' value='Click to check for palindrome'
onClick='validate();return false;'>
As You did not declare a <form>,
the return false is not necessary.
>

<span id='results'></span>
</td>
</tr>

</table>
You did not declare a table.
<script type="text/javascript" language="Javascript">
<script type='text/javascript'>
will do.
<!--
do not use <!-- in the 21st century.
var forward;
var backward;

function validate()
{
var s = "";
forward = "";
backward = "";

var p = document.getElementById( "phrase" ).value;

if ( p == null || p.length == 0 ) {
a text input field can be zero length not null
printResults(0, "A blank string is not valid. Try entering
some text.");
}

p = p.toLowerCase();

var regex = new RegExp( /[a-z]/ );

for (i = 0; i < p.length; i++) {
if ( regex.test( p.charAt( i ) ) ) {
s += p.charAt( i );
}
}

for (i = 0; i < s.length; i++) {
forward += s.charAt( i );
backward += s.charAt( s.length - 1 - i );
}

if ( forward == backward )
{
printResults( 1 );
}
else
{
printResults( 0 );
}
}
Wow, the whole ting can be done like this:

================= palindrome.html =========================
<input id='phrase' type='text'><br>
<input type='submit'
value='Click to check for palindrome'
onClick='isPalindrome();'>
<div id='results'></div>
<script type='text/javascript'>

function isPalindrome(t){
var p = document.getElementById("phrase").value;
var r = document.getElementById( "results" );
var forward = p.toLowerCase().replace(/[^a-z]/g,'');
if (forward.length>1) {
var backward = forward.split('').reverse().join('');
var pal = (forward == backward ) ?'' :'NOT ';
r.innerHTML = '"' + p + '" is ' + pal + 'a valid palindrome.';
} else {
r.innerHTML = 'String needs at least two letters.';
};
};

</script>
==========================================

// 1 for valid, 0 for not valid
Why? Use true and false in js.
>
function printResults( isValid, msg )
you did not declare msg

{
var valid = "valid palindrome.";
var not_valid = "NOT a valid palindrome.";

var results = document.getElementById( "results" );
var p = document.getElementById( "phrase" ).value;
again?
var out = "Results";

if ( isValid ) {
out += "Yup, " + p + " is a " + valid;
}
else {
out += "Nope, " + p + " is " + not_valid;
}

out += "<br>";

if ( msg != null && msg.length 0 ) {
out += msg + "<br>";
}

if ( !isValid && forward.length 0 && backward.length 0 )
{
out += "[" + forward + "] (forward)<br>" +
"[" + backward + "] (backward)";
}

results.innerHTML = out;
}

function clearFields()
{
document.getElementById( "results" ).innerHTML = "";
var p = document.getElementById( "phrase" );

p.value = "";
p.focus();
}

clearFields();
You clear at the loading of the page, the fileds are emptty anyway.

//-->
do not use, see above.
</script>
</body>
</html>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 8 '08 #2
Thx
<HTML>

<head>
<body>
* * * * <input id='phrase' type='text'><br>
* * * * <input type='submit' value='Click to check for palindrome'
onClick='validate();return false;'>
As You did not declare a <form>,
the return false is not necessary.
* * <span id='results'></span>
* * </td>
</tr>
</table>


You did not declare a table.
what for do I need to declare a table?

<script type="text/javascript" language="Javascript">

<script type='text/javascript'>
will do.

<!-- do not use <!-- in the 21st century.
<!--ZOOM&STOP--><!---what do we use then for html comments?---->

var forward;
var backward;
function validate()
{
* * var s = "";
* * forward = "";
* * backward = "";
* * var p = document.getElementById( "phrase" ).value;
* * if ( p == null || p.length == 0 ) {

a text input field can be zero length not null
* * * * printResults(0, "A blank string is not valid. *Try entering
some text.");
* * }
* * p = p.toLowerCase();
* * var regex = new RegExp( /[a-z]/ );
* * for (i = 0; i < p.length; i++) {
* * * * if ( regex.test( p.charAt( i ) ) ) {
* * * * * * s += p.charAt( i );
* * * * }
* * }
* * for (i = 0; i < s.length; i++) {
* * * * forward += s.charAt( i );
* * * * backward += s.charAt( s.length - 1 - i );
* * }
* * if ( forward == backward )
* * {
* * * * printResults( 1 );
* * }
* * else
* * {
* * * * printResults( 0 );
* * }
}

Wow, the whole ting can be done like this:
I am sure there are different ways to do the same thing.
You can write it in C++ and python, i guess..

From what I see ..the results of validation in your code are still
going to show in html
Not as a prompted answer.
Thanks for your comments, i did improve code a bit.

>
================= palindrome.html =========================
<input id='phrase' type='text'><br>
<input type='submit'
value='Click to check for palindrome'
onClick='isPalindrome();'>
<div id='results'></div>

<script type='text/javascript'>

function isPalindrome(t){
* var p = document.getElementById("phrase").value;
* var r = document.getElementById( "results" );
* var forward = p.toLowerCase().replace(/[^a-z]/g,'');
* if (forward.length>1) {
* * *var backward = forward.split('').reverse().join('');
* * *var pal = (forward == backward ) ?'' :'NOT ';
* * *r.innerHTML = '"' + p + '" is ' + pal + 'a valid palindrome.';
* } else {
* * *r.innerHTML = 'String needs at least two letters.';
* };

};

</script>
==========================================
// 1 for valid, 0 for not valid

Why? Use true and false in js.
function printResults( isValid, msg )

you did not declare msg
{
* * var valid = "valid palindrome.";
* * var not_valid = "NOT a valid palindrome.";
* * var results = document.getElementById( "results" );
* * var p = document.getElementById( "phrase" ).value;

again?
* * var out = "Results";
* * if ( isValid ) {
* * * * out += "Yup, " + p + " is a " + valid;
* * }
* * else {
* * * * out += "Nope, " + p + " is " + not_valid;
* * }
* * out += "<br>";
* * if ( msg != null && msg.length 0 ) {
* * * * out += msg + "<br>";
* * }
* * if ( !isValid && forward.length 0 && backward.length 0 )
* * {
* * * * out += "[" + forward + "] (forward)<br>" +
* * * * * * "[" + backward + "] (backward)";
* * }
* * results.innerHTML = out;
}
You clear at the loading of the page, the fileds are emptty anyway.
do not use, see above.
</script>
</body>
</html>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 8 '08 #3

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

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
39
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
3
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
4
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't...
3
by: Dave Moore | last post by:
Hi All, Ok, here's my problem. I want to open a file and process its contents. However, because it is possible that the file may not exist, I also want to check whether the file() function is...
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
6
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.