Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

A simple program [alert("Something") && checkbox.checked]

simple easy simple program alert checkbox

  • Please log in to reply
3 replies to this topic

#1 bluefenix

bluefenix

    CC Newcomer

  • Member
  • PipPip
  • 11 posts
  • Programming Language:Java, PHP, PL/SQL
  • Learning:C#, JavaScript, Visual Basic .NET

Posted 13 August 2012 - 08:52 AM

Hello everybody. Ive wrote a simple program, more simple than what I usually do, but somehow
it doesnt work. I just want it that when you check the checkbox and click the button an alert
message appears. If a message appears only when the checkbox is checked that works too.
Thanks for reading this, and hopefully youll answer to this post.
Ciao

<div id= "div">

<form id= "row" method= "POST">Dulce/Salado



<input type="checkbox" name="option3" value="International" id= 'inter'> International</input>
<input type="button" value="check" onclick="f()">
</form>
</div>

<script type= "text/javascript">

function f()
{
var inter= document.form.getElementById("inter");

if (inter.checked== true)
{
alert("Something");
}
}
</script>
  • 0

#2 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 13 August 2012 - 09:00 AM

Here:
<form id= "row" method= "POST">Dulce/Salado
				    
		    
					    
					    <input type="checkbox" name="option3" value="International"  id= 'inter'> International</input>
					    <input type="button" value="check" onclick="f()">
				    </form>
			    
			    <script type= "text/javascript">
						  
		    function f()
		    {

		   var inter= document.getElementById("inter");
		    if (inter.checked== true)
		    {
			 alert("Something");
		    }
		    }
</script>

  • 0

#3 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 13 August 2012 - 09:17 AM

Yeah, it's document.getElementById, not document.form.getElementById.
  • 0
Regards,
RR

#4 bluefenix

bluefenix

    CC Newcomer

  • Member
  • PipPip
  • 11 posts
  • Programming Language:Java, PHP, PL/SQL
  • Learning:C#, JavaScript, Visual Basic .NET

Posted 13 August 2012 - 12:23 PM

Now it works, thanks a lot. But how will this be without the button, just the checkbox. When the checkbox is checked display an alert:

<div id= "div">

<form id= "row" method= "POST">Dulce/Salado



<input type="checkbox" name="option3" value="International" id= 'inter'> International</input>

</form>
</div>

<script type= "text/javascript">

function f()
{
var inter= document.getElementById("inter");

if (inter.checked== true)
{
alert("Something");
}
}
</script>
  • 0





Also tagged with one or more of these keywords: simple, easy, simple program, alert, checkbox

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download