/    Sign up×
Community /Pin to ProfileBookmark

Enabling/Disabling <table> via JS function?

Hi,
This is a general question to Enable/Disable obects using Javascript code.

Here is the code. In which if “Enable text fields” RadioButton is clicked then both the “First Name” and “Last Name” text fields become Enable [they are enabled by-default] and if “Disable text fields” RadioButton is pressed then both below text fields become disable. I realize we have to use JS function. But it would be highly appreciated if someone could provide help.

Bye,
Viki.

[code]
[code=php]
<html>
<head>
</head>
<body>

<table>
<td>
<input type=”radio” name=”sex” value=”male”> Enable text fields
<input type=”radio” name=”sex” value=”female”> Disable text fields
</td>

</table>

<table>
First name: <input type=”text” name=”firstname”>
<br>
Last name:
<input type=”text” name=”lastname”>
</table>

</body>
</html>
[/code]

[/CODE]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJul 21.2004 — Hi!

Example without using a function:[code=php]<html>
<head>
</head>
<body>
<form>
<table>
<td>
<input type="radio" name="sex" value="male" onclick="if(this.checked){this.form.firstname.disabled=false;this.form.lastname.disabled=false;}"> Enable text fields
<input type="radio" name="sex" value="female" onclick="if(this.checked){this.form.firstname.disabled=true;this.form.lastname.disabled=true;}"> Disable text fields
</td>
</table>
<table>
First name: <input type="text" name="firstname">
<br>
Last name:
<input type="text" name="lastname">
</table>
</form>
</body>
</html>[/code]
Cheers - Pit
Copy linkTweet thisAlerts:
@VikiauthorJul 21.2004 — Hi,

Example using a function:

[code=php]


&lt;html&gt;
&lt;head&gt;

<i> </i> &lt;script type="text/javascript"&gt;
function disableTable(txt1)
{

if(txt1.checked){txt1.form.firstname.disabled=true;txt1.form.lastname.disabled=true;}



}


function enableTable(txt1)
{

if(txt1.checked){txt1.form.firstname.disabled=false;txt1.form.lastname.disabled=false;}


}
&lt;/script&gt;



&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
&lt;table&gt;
&lt;td&gt;
&lt;input type="radio" name="sex" value="male" onclick="enableTable(this)" &gt; Enable text fields
&lt;input type="radio" name="sex" value="female" onclick="disableTable(this)"&gt; Disable text fields
&lt;/td&gt;
&lt;/table&gt;
&lt;table&gt;
First name: &lt;input type="text" name="firstname"&gt;
&lt;br&gt;
Last name:
&lt;input type="text" name="lastname"&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

[/code]

Bye,

Viki.

NOTE: I don't know why my above code is partially colored. Its something with vB code.
Copy linkTweet thisAlerts:
@PittimannJul 21.2004 — Hi!I don't know why my above code is partially colored.[/QUOTE]It is because you wrapped your code in the php stuff.

Good luck!

Bye - Pit
Copy linkTweet thisAlerts:
@VikiauthorJul 21.2004 — Hi,

Pit, what you use while presenting the code? only ['PHP'] tag or ['CODE] tag also?

Bye,

Viki.
Copy linkTweet thisAlerts:
@PittimannJul 21.2004 — Hi!

I mostly use php, but code sometimes, too. And sometimes, I send small snippets without one of the two.

Cheers - Pit
×

Success!

Help @Viki 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...