Kimara
05-05-2003, 09:44 AM
Hiya folks
I have a little project for a school i am trying to finish for tommorrow, all is done except one module.
The pupils have 12 english words, and they type their own version of the words into a form.
They then write a sentance using the english words and press a button to convert ANY of the 12 english words used into their version of the wors.
I am playing around with spli/join and RegExp functions at the moment, but time is ticking away and I could really do with some help, so if theres anyone out there who can help me, it would be very much appreciated.
CODE SO FAR:
<script language="JavaScript" type="text/javascript
oldWordArray = new Array(12)
oldWordArray = ["teachers","my house","tonight","bus","food","bike","enemies","school","car","tommorrow","parents","friends"]
function fillArr() {
var wordArray = new Array()
for(i=0;i<12;i++){
wordArray[i] = document.forms[0].elements[i].value
//alert(wordArray[i])
}
var FullString = document.forms[0].english.value
for(var i=0;i<wordArray.length;i++){
var SelectedString = oldWordArray[i]
var ReplaceString = wordArray[i]
var NewString = FullString.split(oldWordArray[i]).join(wordArray[i])
document.forms[0].english.value = NewString
}
}
</script>
AND THE FORM IS SIMPLY: (table formatting take out for clarity)
<form name="form1">
<input name="Word0" type="text" class="textfields" id="Word0" size="25" maxlength="18">
<input name="Word1" type="text" class="textfields" id="Word1" size="25" maxlength="18">
<input name="Word2" type="text" class="textfields" id="Word2" size="25" maxlength="18">
<input name="Word3" type="text" class="textfields" id="Word3" size="25" maxlength="18">
<input name="Word4" type="text" class="textfields" id="Word4" size="25" maxlength="18">
<input name="Word5" type="text" class="textfields" id="Word5" size="25" maxlength="18">>>
<input name="Word6" type="text" class="textfields" id="Word6" size="25" maxlength="18">
<input name="Word7" type="text" class="textfields" id="Word7" size="25" maxlength="18">
<input name="Word8" type="text" class="textfields" id="Word8" size="25" maxlength="18">
<input name="Word9" type="text" class="textfields" id="Word9" size="25" maxlength="18">
<input name="Word10" type="text" class="textfields" id="Word10" size="25" maxlength="18">
<input name="Word11" type="text" class="textfields" id="Word11" size="25" maxlength="18">
<textarea name="english" cols="60" rows="4" id="english"> </textarea>
<input type="button" name="convert" class="buttons" value="PRESS TO CONVERT INTO YOUR LANGUAGE" onClick="fillArr()">
</form>
I hope that someone can point me in the right direction
thanks for your time
kimara
I have a little project for a school i am trying to finish for tommorrow, all is done except one module.
The pupils have 12 english words, and they type their own version of the words into a form.
They then write a sentance using the english words and press a button to convert ANY of the 12 english words used into their version of the wors.
I am playing around with spli/join and RegExp functions at the moment, but time is ticking away and I could really do with some help, so if theres anyone out there who can help me, it would be very much appreciated.
CODE SO FAR:
<script language="JavaScript" type="text/javascript
oldWordArray = new Array(12)
oldWordArray = ["teachers","my house","tonight","bus","food","bike","enemies","school","car","tommorrow","parents","friends"]
function fillArr() {
var wordArray = new Array()
for(i=0;i<12;i++){
wordArray[i] = document.forms[0].elements[i].value
//alert(wordArray[i])
}
var FullString = document.forms[0].english.value
for(var i=0;i<wordArray.length;i++){
var SelectedString = oldWordArray[i]
var ReplaceString = wordArray[i]
var NewString = FullString.split(oldWordArray[i]).join(wordArray[i])
document.forms[0].english.value = NewString
}
}
</script>
AND THE FORM IS SIMPLY: (table formatting take out for clarity)
<form name="form1">
<input name="Word0" type="text" class="textfields" id="Word0" size="25" maxlength="18">
<input name="Word1" type="text" class="textfields" id="Word1" size="25" maxlength="18">
<input name="Word2" type="text" class="textfields" id="Word2" size="25" maxlength="18">
<input name="Word3" type="text" class="textfields" id="Word3" size="25" maxlength="18">
<input name="Word4" type="text" class="textfields" id="Word4" size="25" maxlength="18">
<input name="Word5" type="text" class="textfields" id="Word5" size="25" maxlength="18">>>
<input name="Word6" type="text" class="textfields" id="Word6" size="25" maxlength="18">
<input name="Word7" type="text" class="textfields" id="Word7" size="25" maxlength="18">
<input name="Word8" type="text" class="textfields" id="Word8" size="25" maxlength="18">
<input name="Word9" type="text" class="textfields" id="Word9" size="25" maxlength="18">
<input name="Word10" type="text" class="textfields" id="Word10" size="25" maxlength="18">
<input name="Word11" type="text" class="textfields" id="Word11" size="25" maxlength="18">
<textarea name="english" cols="60" rows="4" id="english"> </textarea>
<input type="button" name="convert" class="buttons" value="PRESS TO CONVERT INTO YOUR LANGUAGE" onClick="fillArr()">
</form>
I hope that someone can point me in the right direction
thanks for your time
kimara