View Full Version : A few simple things I Need to know
avelonx
12-08-2002, 02:45 PM
How would I return something like this without it screwing up:
<script>
var a=hello
var b=world
document.test.value=a/b
</script>
and it want it to return Hello/World
and also when I fill in a textarea with some data and then later when I do it again if overwrites whats in the box. How would I append further data onto the previous?
im reading tutorials , but I just cant figure it out.
Thanks for your time
smeagol
12-08-2002, 03:09 PM
Hey,
If you want to return the value "hello world" you would need to alter your script to the following:
<script>
var a='hello ';
var b='world';
document.test.value=a + b;
</script>
To keep the value inside a textarea and append it's value, you would need to do something like this:
In this example, the textarea is named "txtValue":
<script>
document.form1.txtValue += 'This is the appended text';
</script>
Basically, the += means that the object on the left of the += will keep it's current value, plus the value on the right of the +=.
Hope this helps,
Smeagol
Graeme Hackston
12-08-2002, 03:33 PM
<html>
<head>
</head>
<body>
<form name="MyForm">
<input name="MyInput" type="text">
</form>
<script>
a = 'hello'
b = 'world'
document.MyForm.MyInput.value = a.replace(a.charAt(0),a.charAt(0).toUpperCase()) + '/' + b.replace(b.charAt(0),b.charAt(0).toUpperCase())
</script>
<a href="#" onclick="document.MyForm.MyInput.value = document.MyForm.MyInput.value + ' more stuff'">test</a>
</body>
</html>
You'll find this page helpful
http://www.devguru.com/Technologies/ecmascript/quickref/string.html
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.