ic: website ic:blog
  ic: website Home · Archives · Photo Gallery · ic: forum RSS logo - thanks to www.nineteenlabs.comWeb feed (RSS)  
The life and times of james Hart: his family, his music, life in Luton and his occasional escapes onto the internet.

« this service will be delayed for... | Main | nothing taken for granted... »

Wednesday, 13 October 2004

Fun... erm... with javascript [techie]

Today I was mostly learning about javascript. One of my colleagues had asked if I could make a webpage that took some essential information out of a long line, and, as I like to keep my hand in programming, I thought I'd have a go. All the research was done over breakfast, and I managed to get most of it going on the coach to work. That all the functions are CaseSensitive, and you have to use strange functions to change characters on a web page makes for a fairly frustrating task getting it to work. The things I learned, in case you're interested are:

An example of how to change a link on a web page using javascript (and a form)

<html>
<head>

<script language="JavaScript1.2">
<!--

function changeurl() {

//define some variables
var adstr;

//Get the string from a text box called "Textybox" in form called "Formy"
adstr = document.Formy.Textybox.value ;

//Change the URL with NAME="clickurl" to the value in the text box
document.getElementById('clickurl').href=adstr;

}
-->
</script>

</head>

<body>

<FORM name="Formy" action=""> Filename: <INPUT type=text name="Textybox" size=30 maxlength=175 value=""> <input type="button" value="Click!" onclick="changeurl()"></FORM> <p> <A HREF="#" name="clickurl">click this link</A>

</body>
</html>

An example of how to change text on a web page using javascript (and a form)

<html>
<head>

<script language="JavaScript1.2">
<!--

function changetext() {
//define some variables
var textstr;

//Get the string from a text box called "Textybox" in form called "Formy"
textstr = document.Formy.Textybox.value ;

//Change the text area with DIV ID="textybit" to the value in the text box
document.all.textybit.innerHTML=textstr ;

}
-->
</script>

</head>

<body>

<FORM name="Formy" action=""> Filename: <INPUT type=text name="Textybox" size=30 maxlength=175 value=""> <input type="button" value="Click!" onclick="changetext()"></FORM> <p>
<div ID="textybit">This is what it was...</div>

</body>
</html>

I expect this is probably quite elementary to the experts in the world, but I struggled with "document.write" creating a fresh new webpage, which isn't really what I wanted...

Posted by james at October 13, 2004 8:49 PM


 
This site is owned and operated by Image Communications, including all content and stuff.
It's powered by Movable Type 5.2