...

View Full Version : Help plz



wavyado
09-27-2008, 10:05 PM
i have two questions

1)
i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function


2)

A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function


i hope any1 will write me those scripts.
Thanks all of u :)

Millenia
09-27-2008, 10:31 PM
i have two questions

1)
i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function


2)

A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function


i hope any1 will write me those scripts.
Thanks all of u :)

Were here to help not to do everything for you.
If you don't know how to do it then I suggest you learn.

Unless you want to start it and we can help you.

mattyod
09-27-2008, 11:17 PM
i have two questions

1)
i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function


2)

A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function


i hope any1 will write me those scripts.
Thanks all of u :)

1: I want you to make some sense.

2: I want you to make some effort.

wavyado
09-27-2008, 11:28 PM
Were here to help not to do everything for you.
If you don't know how to do it then I suggest you learn.

Unless you want to start it and we can help you.


in the 1st question

<html>
<head>
<script>
function Convert(){

var a=document.f.t1.value;
var b=document.f.t2.value;
var i;

for(i=0;i<=a.length;i++)
{
document.f.t2.value=b.replace(a.charAt(i),"x");
}







}


</script>
</head>

<body>
<form name="f">
<table>
<tr>
<td>Enter <td><input type=text name="t1">
</tr>

<tr>
<td>Enter <td><input type=text name="t2">
</tr>

<tr>
<td><input type=button value=convert onClick="Convert()">
</tr>




</table>

</form>

</body>
</html>


the second 1

var a=document.f.t1.value;

var i;

for (i = 0; i < a.length; i++)
{
var c = a.charAt(i);

if (!isDigit(c))


{alert("adsads");}
}



so are they right ?

wavyado
09-27-2008, 11:29 PM
1: I want you to make some sense.

2: I want you to make some effort.

in the 1st question

<html>
<head>
<script>
function Convert(){

var a=document.f.t1.value;
var b=document.f.t2.value;
var i;

for(i=0;i<=a.length;i++)
{
document.f.t2.value=b.replace(a.charAt(i),"x");
}







}


</script>
</head>

<body>
<form name="f">
<table>
<tr>
<td>Enter <td><input type=text name="t1">
</tr>

<tr>
<td>Enter <td><input type=text name="t2">
</tr>

<tr>
<td><input type=button value=convert onClick="Convert()">
</tr>




</table>

</form>

</body>
</html>


the second 1

var a=document.f.t1.value;

var i;

for (i = 0; i < a.length; i++)
{
var c = a.charAt(i);

if (!isDigit(c))


{alert("adsads");}
}



so are they right ?

_Aerospace_Eng_
09-28-2008, 04:53 AM
Does it work?

wavyado
09-29-2008, 02:49 AM
so will any1 help me or what ?

rangana
09-29-2008, 06:12 AM
First of all, try to change your title, make it a little bit descriptive as to the problem you're experiencing right now.

Secondly, your question is confusing.


[B]
1) i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function
2) A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function



For the first one, you can do a global replace:


<script type="text/javascript">
window.onload=function(){
var el=document.getElementById('test');
el.firstChild.nodeValue=el.firstChild.nodeValue.replace(/[a-z\d]/gi,'x');
}
</script>
<p id="test">
The quick brown fox jumps over the lazy dog.
</p>


...but the second statement in your first question does'nt makes sense.

For your second question:


<script type="text/javascript">
window.onload=function(){
var el=document.getElementById('test');
alert((el.innerHTML.length>0)?'Great! You have long characters.':'Please lengthen your characters.');
}
</script>
<p id="test">
The quick brown fox jumps over the lazy dog.
</p>


The second statement is confusing still.

And for the last one:

so will any1 help me or what ?

Patience is a virtue, and it seemed you are not living on it.

Hope that makes sense.

wavyado
09-29-2008, 12:41 PM
First of all, try to change your title, make it a little bit descriptive as to the problem you're experiencing right now.

Secondly, your question is confusing.




For the first one, you can do a global replace:


<script type="text/javascript">
window.onload=function(){
var el=document.getElementById('test');
el.firstChild.nodeValue=el.firstChild.nodeValue.replace(/[a-z\d]/gi,'x');
}
</script>
<p id="test">
The quick brown fox jumps over the lazy dog.
</p>


...but the second statement in your first question does'nt makes sense.

For your second question:


<script type="text/javascript">
window.onload=function(){
var el=document.getElementById('test');
alert((el.innerHTML.length>0)?'Great! You have long characters.':'Please lengthen your characters.');
}
</script>
<p id="test">
The quick brown fox jumps over the lazy dog.
</p>


The second statement is confusing still.

And for the last one:


Patience is a virtue, and it seemed you are not living on it.

Hope that makes sense.

First of all, Thanks very much rangana, i really owe u, cause u really helped me in the first question, and in the secod question, which is :

A javascript function that return 'true' when a string contains at least one digit.

for example: if you entered a string,let say "can any1 help" so this string contain the "1" digit, in this case, an alert prompt that this string contain a digit.

and relating 4 the 1st question, in /[a-z\d]/gi, i understand a-z is that all Character between a and z, but i didnt understand the \d and the /gi,to what they refer ?

Hope you wuill again answer my questions.

Thanks for your help and your cooperation :)

rangana
09-30-2008, 02:19 AM
Use this instead:


<script type="text/javascript">
window.onload=function(){
var el=document.getElementById('test');
alert((el.innerHTML.match(/\d/g))?'Great! You have a digit on it.':'Sorry, there\'s no digit on it.');
}
</script>
<p id="test">
The quick brown fox jumps over the lazy dog.
</p>


\d matches a digit, the same as you do [0-9].

gi are modifier which stands for global pattern matching and case-insensitive pattern matching respectively.

Hope that makes sense.

wavyado
09-30-2008, 04:10 PM
Use this instead:


<script type="text/javascript">
window.onload=function(){
var el=document.getElementById('test');
alert((el.innerHTML.match(/\d/g))?'Great! You have a digit on it.':'Sorry, there\'s no digit on it.');
}
</script>
<p id="test">
The quick brown fox jumps over the lazy dog.
</p>


\d matches a digit, the same as you do [0-9].

gi are modifier which stands for global pattern matching and case-insensitive pattern matching respectively.

Hope that makes sense.

Thanks rangana, You Really helped me. I wish some day i can help you :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum