<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Chapt11_1</title>
<script type = "text/javascript">
<!--
var myString = document.getElementById("formText").value;
var newString = "and";
function convertit()
{
for(var i = 0; i< myString.length;i++)
{
if(myString.charAt(i) == "&")
newString += "and";
else
newString +=myString.charAt(i);
}
}
// -->
</script>
</head>
<body>
<form>
<input type="text" id="formText" onblur="convertit()" />
</form>
</body>
</html>
Help with conversion
Page 1 of 12 Replies - 417 Views - Last Post: 17 April 2011 - 08:10 AM
#1
Help with conversion
Posted 16 April 2011 - 10:14 PM
Hi I'm having trouble (with an assignment) converting ampersands to "and". I'm out of ideas on how to get this functional. And tips or direction would be greatly appreciated.
Replies To: Help with conversion
#2
Re: Help with conversion
Posted 17 April 2011 - 12:44 AM
Hey.
Firstly, you're probably going to want to put the myString and newString variables inside the function, or they will just be set once when the page loads, which means the myString variable will always be the initial value of your formText input, which is presumably empty.
That said, you may want to check out the String.replace function.
Firstly, you're probably going to want to put the myString and newString variables inside the function, or they will just be set once when the page loads, which means the myString variable will always be the initial value of your formText input, which is presumably empty.
That said, you may want to check out the String.replace function.
#3
Re: Help with conversion
Posted 17 April 2011 - 08:10 AM
Atli, on 17 April 2011 - 12:44 AM, said:
Hey.
Firstly, you're probably going to want to put the myString and newString variables inside the function, or they will just be set once when the page loads, which means the myString variable will always be the initial value of your formText input, which is presumably empty.
That said, you may want to check out the String.replace function.
Firstly, you're probably going to want to put the myString and newString variables inside the function, or they will just be set once when the page loads, which means the myString variable will always be the initial value of your formText input, which is presumably empty.
That said, you may want to check out the String.replace function.
Thank you so much!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|