Solved

Problem with Visibility of image (input type)

Posted on 2007-11-20
4
657 Views
Last Modified: 2012-08-14
I have code that I want to display a new textbox (txt2) & search icon (search2) when the first textbox is populated & clicked away from.  I am able to get this to display the next textbiox & the image only if I use IMG tag; but not if I use input type="image", which is what I'd like here. I have also tried it with the display=none/block attribute as well.


<script language="javascript">

   function showField(i, val) {

      if ((i==1) && (val!="")){

         document.frmItems.txt2.style.visibility='visible';

         document.frmItems.search2.style.visibility='visible';

      }

</script
 

//body
 

<table>

   <tr><td><input name="txt1" type="text" onblur="showField(1, this.value);" size="15" /></td>

   <td><input type="image" name="search1" src="icon_search.jpg"  /></td></tr>
 

   <tr><td><input type="text" name="txt2" onblur="showField(2, this.value);" style="visibility:hidden" size="15" /></td>

   <td><input type="image" id="search2" name="search2" src="icon_search.jpg" style="visibility:hiddene" />

</td> </tr> </table>

Open in new window

0
Comment
Question by:katiep23
  • 2
4 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20321926
Check your spelling

visibility:hiddene
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 100 total points
ID: 20321981
The form.elements collection doesn't contain input elements with type="image". You have to access the image button using the id:
document.getElementById('search2').style.visibility='visible';

Open in new window

0
 
LVL 12

Expert Comment

by:netsmithcentral
ID: 20322008
There were a couple of syntactic problems with the snippet you posted.  Try this:

<html>
<head>
<script language="javascript">
   function showField(i, val) {
      if ((i==1) && (val!="")){
         document.getElementById('txt2').style.display = 'block';
         document.getElementById('search2').style.display = 'block';
      }
      }
</script>
</head>
<body>
<table>
   <tr><td><input name="txt1" type="text" onblur="showField(1, this.value);" size="15" /></td>
   <td><input type="image" name="search1" src="icon_search.jpg"  /></td></tr>
 
   <tr><td><input type="text" name="txt2" id="txt2" onblur="showField(2, this.value);" style="display: none" size="15" /></td>
   <td><input type="image" id="search2" name="search2" src="icon_search.jpg" style="display: none" />
</td> </tr> </table>
</body>
</html>
0
 
LVL 17

Expert Comment

by:gops1
ID: 20322032
or this way:
<html>

	<head>

		<title>Script Demo Gops</title>

		<script language="javascript">

			function showField(i, val) {

				if ((i==1) && (val!="")){

					document.getElementById('row2').style.visibility='visible';

				}

			}
 

        </script>

     </head>

<body>

	<form name="frmItems">

		<table>

			<tr>

				<td><input name="txt1" type="text" onblur="showField(1, this.value);" size="15" /></td>

				<td><input type="image" name="search1" src="icon_search.jpg"  /></td>

			</tr>

			<tr id="row2" style="visibility:hidden">

				<td><input type="text" name="txt2" onblur="showField(2, this.value);" size="15" /></td>

				<td><input type="image" name="search2" src="icon_search.jpg" /></td>

			</tr>

		</table>

	</form>

</body>

</html>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now