Click to See Complete Forum and Search --> : this is driving me crazy!


hungrydino
02-13-2003, 06:59 PM
Can anyone spot the bug??? Because I've been trying for three days and can't. The purpose of the script is to take the " out of a sentence and replace it with ".


<script>
function runfunction () {
var thestring = self.test.box.value;
var thestring_array = thestring.split('"');
var theresult
var counterlimit = thestring_array.length
var counter = 0
var box_value = ""
var theresult_counter

do {
theresult_counter = 0
do {
theresult[theresult_counter] = thestring_array[counter] + """;
counter++
theresult_counter++
}
while (counter < counterlimit && theresult_counter < 2)



box_value = box_value + "document.writeln(\"" + theresult[0] + theresult[1] + "\");";
}

while (counter < counterlimit)


self.test.box2.value = box_value



}

</script>

Charles
02-13-2003, 07:07 PM
Please be more clear about what it is that you are trying to accomplish. This looks like a one line problem, but the board seems to have altrered your post.

hungrydino
02-13-2003, 07:18 PM
Yes sorry - should have known. I'm trying to replace any quotation mark ( " ) with its code & # 3 4 ;

<script>
function runfunction () {
var thestring = self.test.box.value;
var thestring_array = thestring.split('"'); // this is a " between two '
var theresult
var counterlimit = thestring_array.length
var counter = 0
var box_value = ""
var theresult_counter

do {
theresult_counter = 0
do {
theresult[theresult_counter] = thestring_array[counter] + "& # 3 4 ;";
counter++
theresult_counter++
}
while (counter < counterlimit && theresult_counter < 2)



box_value = box_value + "document.writeln(\"" + theresult[0] + theresult[1] + "\");";
}

while (counter < counterlimit)


self.test.box2.value = box_value



}

</script>

Charles
02-13-2003, 07:24 PM
<script type="text/javascript">
<!--
alert('"Hello, World!"'.replace(/"/g,'&amp;#34;'))
// -->
</script>

hungrydino
02-13-2003, 07:24 PM
the html has two multiline text boxes - if i put this...

sfd " fsd " sdf

into the first text box, hit the magic button, this should pop out...

sfd & # 3 4 ; fsd & # 3 4 ; sdf & # 3 4 ;

that's without the spaces in & # 3 4 ; of course.

Right now the code adds the extra quote after the last portion but I can fix that later.

Charles
02-13-2003, 07:26 PM
<script type="text/javascript">
<!--
alert('sfd " fsd " sdf'.replace(/"/g,'"'))
// -->
</script>

hungrydino
02-13-2003, 07:37 PM
I'm kind of with you except for I don't know how to change it while keeping it in the variable - I tried this:

var thestring.replace(/"/g,'"')

or this if that didnt show
var thestring.replace(/"/g,'& # 3 4 ;')

check out these two pages to see what I'm trying to do.

www.magictrickman.com/testing.htm
www.magictrickman.com/testing1.htm

When you copy and paste that line into the box on the first page the correct output shows up in the box below. That's the code I need to be generated from all this code. The point of writing the code for the second page was so that if a long string was entered into the first box, it could cut the code up between several document.writeln statements.

That's where the problem showed up.