Hi Everyone,
I am trying the acheieve something which I understand is quite simple but to beginner like me its a headache.
Is someone able to point me in the right direction please?
I am trying to achieve a page with many images and an input form that allows the user to select which pictures they want to be visible and hide the others.
I am trying to do it so the javascipt will search all the images, by their name(or even id not bothered which) and then if the name matches that entered in the form then the these pictures are displayed and the others are hidden.
I am getting confused between the getElementbyId , getElementsbyId and type of variable information it is gathering. After echo the result I can only seem to get the number of results and therefore can’t seem to apply a style change to these.
Here is something, very little I know of what I’m working with.
[code]
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script type=”text/javascript”>
function checkit()
{
var imgs=document.getElementsByTagName(“IMG”);
for (var n=0;n<imgs.length;n++)
if (imgs[n].className== document.testform.myinput.value)
{
imgs[n].style.display = ‘hidden’;
}
else
{
imgs[n].style.display = ‘visible’;
}
}
</script>
</head>
<body>
<form name=”testform” onsubmit=”checkit(this)” >
<input type=”text” name=”myinput”>
<input type=”submit” />
<img src=”images/pic.GIF” class=”first”>
<img src=”images/pic2.GIF” class=”second”>
</form >
</body>
</html>
Any comments or pointer would be greatfully accepted.
Many Thanks
Adrian