aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Making a checkbox perform like a button Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Making a checkbox perform like a button" Watch "Making a checkbox perform like a button" New topic
Author

Making a checkbox perform like a button

Timothy M Smith
Greenhorn

Joined: Aug 19, 2009
Posts: 2
Hi,

I am trying to run a script silenty by asking the user to tick a check box.

So the check box goes from empty to being a cross, but also runs the script.

I am sure I have seen this before but I can't find a working example.


Your help is very much appreciated as I am running out of hair ... :-)

Tim
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Welcome to JavaRanch

I was going to tell you to go to the JCheckBox API and find what Listeners you can add to a JCheckBox. Then I saw it gives a link to the Java Tutorials where you can find an example. I think that uses a ChangeListener.

You can also add an ActionListener, but I think that only fires when the box is checked, not un-checked.

Since we usually discuss these things on the Swing forum I shall move you there.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

"tim jigsaw", please check your private messages regarding an important administrative matter.

Thank you.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
a checkbox is a button

from the apidocs

Timothy M Smith
Greenhorn

Joined: Aug 19, 2009
Posts: 2
Thanks for your comments and help so far, but I am still a little stuck here.

I am trying to build a WiFi landing page and essentially I want the user to agree to the t & c's, by doing this they send the user and password to my box and it opens the internet portal up to the user.

Below is the full html and the small Java script that checks and ensures the user agrees to the terms and conditions etc

What I am trying to do here is get the checkbox to run the login form.

So obviously changing the checkbox to button does this, But I want to add further functionality to my page and want to run a further script that will direct them to another URL. (this I can do as I found this on your site already!!)

However you may want to point me in the direction of the tutorial as this is alot to ask, but I did read the posts but I am still some what lost!!!


<html>
<head>
<title>Login Script</title>
<SCRIPT LANGUAGE="JavaScript">

function checkCheckBox(f){
if (f.agree.checked == false )
{
alert('Please read the terms and conditions and check the box to continue.');
return false;
}else
return true;
}

</script>

</head>
<body background="bg.gif" style="padding: 0px; margin: 20px;">

<center>

<div style="width: 750px; height: 450px; padding: 0px; margin: 0px; background-image: url(main.gif);">

<table width="750" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="375" rowspan="2" align="center" valign="bottom">

<form name="weblogin" action="" method="POST" onsubmit="return checkCheckBox(this)" style="padding: 0px; margin: 0px;">
<INPUT type="hidden" value="wba_login" name="fname">
<INPUT type="hidden" maxLength="32" size="15" name="username" value="user">
<INPUT type="hidden" maxLength="32" size="15" name="key" value="password">


<TEXTAREA NAME="conditions" style="width: 340px; height: 60px; font-family: verdana; font-size: 9px; line-height: 11px; font-weight: bold; color: rgb(0,0,0); margin-bottom: 15px;">
Terms and Conditions </TEXTAREA>
etc etc etc

</td>
<td width="375" height="400" valign="bottom">
<input type="checkbox" value="0" name="agree" style="margin: 0px; padding: 0px; height: 10px; width: 10px; margin-left: 50px; margin-bottom: 2px;">
</td>
</tr>

<tr>
<td align="center" height="50">
<INPUT type=image name="search" src="button.gif" border="0">
</form>
</td>
</tr>

Thanks again,
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1786
    
    2
This is a Java forum.

Your question is about HTML and JavaScript.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8430

Moving to a more appropriate forum.


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
When you post code, please use code tags. Make it easier to read



Eric

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Making a checkbox perform like a button
 
Similar Threads
Strange - Page Submits!!!
In struts el how to get checkbox status
geting focus on radio button
Selecting a particular row in <table> tag used.
drop down list box height