/    Sign up×
Community /Pin to ProfileBookmark

How to check if check box is selected?

Hi Guys,
I want to write a javascript which does following:
Please see HTML code>
When page is loaded first time:
Clone User Text field and it button “Add and Clone” should be dislabed.

When user clicks on Checkbox First Name and Last Name should be disabled and Clone User and Add and Clone should be enables.
Thanks

<html>

<head>
<title></title>
<style>

</style>

<script language=”javascript”>

</script>
</head>
<Script type=”text/javascript”>
function toggle(chk) {
if (this.checked)
alert(“Checked”);
else
alert(“Not Checked.”)

}

</Script>
<body>
<form>
<input type=”checkbox” name=”option1″ value=”name” id=”check” onClick=”toggle(‘option1’)”>

<!–div id=”toggle” style=”display: none;” –>
<tr >
<td><br>
First name:
</td>
<td>
<input type=”text” name=”firstname” id=”firstname”>
</td>
</tr>
<!–/div–>
<tr>
<td><br>
Last name:
</td>
<td>
<input type=”text” name=”lastname” id=”lastname”>
</td>
<td>
<input type=”button” name=”adduser” Value = “Add User” id=”adduser”>
</td>
</tr>

<tr>
<td><br>
Clone User
</td>
<td>
<input type=”text” name=”clone” id=”clone”>
</td>
<td>
<input type=”button” name=”addandClone” Value = “Add And Clone” id=”clonebtn”>
</td>

</tr>

</form>
</body>

</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SheldonMay 02.2006 — How come no body in th javascript forum uses VB Tags?

Its requested by everyone and stated in the "READ THIS BEFORE YOU POST" thread!
Copy linkTweet thisAlerts:
@balloonbuffoonMay 02.2006 — Try changing this:
[CODE]<Script type="text/javascript">
function toggle(chk) {
if (this.checked)
alert("Checked");
else
alert("Not Checked.")

}

</Script>
<body>
<form>
<input type="checkbox" name="option1" value="name" id="check" onClick="toggle('option1')">[/CODE]
to this:
[CODE]<script type="text/javascript">
function toggle(chk) {
if (chk.checked)
alert("Checked");
else
alert("Not Checked.")

}

</script>
<body>
<form>
<input type="checkbox" name="option1" value="name" id="check" onClick="toggle(this)">[/CODE]
(And please use [ CODE][/CODE] or [ HTML][/code] tags next time. ?)--Steve
×

Success!

Help @alidar777 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...