Solved

Code to use cross box instead of checkbox in form

Posted on 2010-09-23
9
733 Views
Last Modified: 2012-05-10
i need code which show cross on click not tick
0
Comment
Question by:savsoft
  • 5
  • 4
9 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33750981
if you are looking for a javascript code to check if the checkbox if checked or not, then see
http://www.w3schools.com/js/tryit.asp?filename=try_dom_input_checked

for example, if the html is
<input type="checkbox" id="myCheck" />

this method will return the true if the checkbox is ticked
function ischecked(checkboxId)
{
    return document.getElementById(checkboxId).checked;
}
alert(ischecked("myCheck"));
0
 

Author Comment

by:savsoft
ID: 33751067
is it java script code ?
Please write full code...
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33751074
see if this helps

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<script>
		function ischecked(checkboxId)
		{
			return document.getElementById(checkboxId).checked;
		}
	</script>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
	<input type="checkbox" id="myCheck" onclick="alert(ischecked(this.id))"/>
</BODY>
</HTML>

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:savsoft
ID: 33751104
But it shows message about false when untick.
i want any code which shows red cross in box on click..
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33751186
<<i want any code which shows red cross in box on click..>>
what do you mean? you want to show an read cross image on checkbox toggle?

try this code, replace the image name with yours
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<script>
		function ischecked(checkboxId)
		{
			return document.getElementById(checkboxId).checked;
		}
		function toggleImage(checkboxId)
		{
			if ( ischecked( checkboxId ) )
			{
				document.getElementById("img1").style.display = "block";
			}
			else
			{
				document.getElementById("img1").style.display = "none";
			}
		}
	</script>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
	<input type="checkbox" id="myCheck" onclick="toggleImage(this.id)"/>
	<img src="21022009.jpg" width="50px" height="50px" style="display:none" id="img1">
</BODY>
</HTML>

Open in new window

0
 

Author Comment

by:savsoft
ID: 33751493
Thank you gurvinder,

please read my requirement carefully..

what does checkbox mean?: it is a box which shows tick mark in square box

but i want crossbox ( which shows cross "x" in square box on click

IT SHOWS CROSS BOX IN THE BOX WHERE WE CLICK NOT BELOW...................

Please see attached image


x.JPG
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 33751595
ohh, so you want the image to toggle at the onclick event right?

then check this.
you need to replace the images name

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<script>
		function toggleImage(imageId)
		{
			var imageName = document.getElementById("img1").src ;
			if ( imageName == "21022009.jpg" )
			{
				imageName = "18072010.jpg";
			}
			else
			{
				imageName = "21022009.jpg";
			}
			document.getElementById("img1").src = imageName;
		}
	</script>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
	<img src="21022009.jpg" width="50px" height="50px" id="img1" onclick="toggleImage(this.id)">
</BODY>
</HTML>

Open in new window

0
 

Author Comment

by:savsoft
ID: 33866190
still i did not get answer.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33867005
please mention what is wrong with the output of code i have pasted above, please be specific.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
css, html 5 42
Safari On Gmail only html 12 56
Why a span is lower 2 20
Button and js nou working 3 8
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

809 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