Q1- Hi all, I have a project that there is a page with textbox and textarea and 2 buttons, I should write a string (word or more) in the textbox then when I click on the “Search” button it should open a window.prompt, which I should enter a char or word and then it should return how many times this word or character is found in the string entered in the textbox and then show it in the textarea, Here is what I have but it’s not working:
[CODE]
<html>
<head>
<title>Page 1</title>
<script type=”text/javascript”>
function search()
{
var a = window.prompt(“Enter the string you want to search for:”,0);
var b = F1.T1.value;
var count = 0;
for (var i = 1; i <= b.length; i++)
{
if (b.indexOf(a,i))
{
count = count + 1;
}
}
F1.A1.value = count;
}
</script>
</head>
<body>
<br /><br />
<form name=”F1″>
<p>Enter value:</p>
<input type=”text” name=”T1″ size=”20″ />
<input type=”button” name=”S1″ value=”Search” onclick=”search()” />
<input type=”button” name=”S2″ value=”Show” onclick=”show()” />
<br />
<p>This is the result:</p>
<textarea cols=”30″ rows=”6″ name=”A1″ /></textarea>
</form>
</body>
</html>
Q2- There is another button named as “Show” .. it should take the string in the textbox and return it like this: (using a function called “show()”..
Ex: if the string is “world” then it should write the following in the textarea:
w
wo
wor
worl
world
So can someone help me please with these two questions,
Thanks in advance,
zeid