Jump to content

[SOLVED] Enabling a text input field ONLY when a checkbox is ticked


Dale_G

Recommended Posts

Hey everyone, as you can see I'm new here.

 

I'm working on a new section for a site.

 

Basically it's a layout creator, mostly, with a few customization options. Basically as you can see from the HTML below, there is a checkbox with the id "network" and a text input field with the id "username".

 

<div style="text-align: left;">
<b>2. Creation</b>
</div>
<br>
Here you can customize
<br><br>
<table align="center" cellpadding="5" width="95%" style="margin: 3px; padding: 5px; border: 2px solid black;">
<tr>
<td align="center">
<table align="center" width="98%" cellspacing="1" cellpadding="3">
<tr>
<td width="50%" style="text-align: center;">Replace the Extended Network Logo with your Dynamic Signature (?)<br><input type="checkbox" id="network" name="network" style="border:none;" value="_s" /></td>
<td width="50%" style="text-align: center;">Hide the Comments section (?)<br><input type="checkbox" id="comments" name="comments" style="border:none;" value="_p" /></td>
</tr>
</table>
<input type="text" id="username" size="20" maxlength="12">
<br>
<font size="1">If you checked "Replace Extended Network Logo" you MUST enter your name here so the Signature can be created. Otherwise your signature WILL NOT DISPLAY.<br><br>If you'd like to keep the Extended Network Logo LEAVE THE ABOVE FIELD BLANK!</font>
<hr>
<input type="button" value="Generate my Layout!" style="text-align: center;" onClick="make_sig()" onSubmit="make_sig()">
<div id="urlbox"></div>
</table>
<br>
</td>
</td>
</table>

 

Basically, I need to know how I can have the username field disabled by default, and then enabled only WHILE the network checkbox is checked.

 

I'm not too sure how to do this. But I have some sort of idea. Perhaps something like this (excuse the sloppy and incorrect structure, this is just to demonstrate)

 

if (document.getElementById("network").checked==true THEN document.getElementById("username").disabled==false)

 

You know, basically something stating WHILE the network checkbox is checked the username field will be enabled and if network is unchecked, username becomes disabled.

 

Thanks. ;)

 

 

Link to comment
Share on other sites

<script language="javascript">

function Newtworking()
{
var cb1 = document.getElementById('network').checked;
if (cb1 == true)
{
  document.getElementById('username').disabled = false;
}
else if (cb1 != true)
{
  document.getElementById('username').disabled = true;
}
}

</script>

<div style="text-align: left;">
<b>2. Creation</b>
</div>
<br>
Here you can customize
<br><br>
<table align="center" cellpadding="5" width="95%" style="margin: 3px; padding: 5px; border: 2px solid black;">
<tr>
<td align="center">
<table align="center" width="98%" cellspacing="1" cellpadding="3">
<tr>
<td width="50%" style="text-align: center;">Replace the Extended Network Logo with your Dynamic Signature (?)<br><input type="checkbox" id="network" name="network" style="border:none;" value="_s" onclick="Newtworking()" /></td>
<td width="50%" style="text-align: center;">Hide the Comments section (?)<br><input type="checkbox" id="comments" name="comments" style="border:none;" value="_p" /></td>
</tr>
</table>
<input type="text" id="username" size="20" maxlength="12" disabled>
<br>
<font size="1">If you checked "Replace Extended Network Logo" you MUST enter your name here so the Signature can be created. Otherwise your signature WILL NOT DISPLAY.<br><br>If you'd like to keep the Extended Network Logo LEAVE THE ABOVE FIELD BLANK!</font>
<hr>
<input type="button" value="Generate my Layout!" style="text-align: center;" onClick="make_sig()" onSubmit="make_sig()">
<div id="urlbox"></div>
</table>
<br>
</td>
</td>
</table>

Link to comment
Share on other sites

<script language="javascript">

function Newtworking()
{
var cb1 = document.getElementById('network').checked;
if (cb1 == true)
{
  document.getElementById('username').disabled = false;
}
else if (cb1 != true)
{
  document.getElementById('username').disabled = true;
}
}

</script>

<div style="text-align: left;">
<b>2. Creation</b>
</div>
<br>
Here you can customize
<br><br>
<table align="center" cellpadding="5" width="95%" style="margin: 3px; padding: 5px; border: 2px solid black;">
<tr>
<td align="center">
<table align="center" width="98%" cellspacing="1" cellpadding="3">
<tr>
<td width="50%" style="text-align: center;">Replace the Extended Network Logo with your Dynamic Signature (?)<br><input type="checkbox" id="network" name="network" style="border:none;" value="_s" onclick="Newtworking()" /></td>
<td width="50%" style="text-align: center;">Hide the Comments section (?)<br><input type="checkbox" id="comments" name="comments" style="border:none;" value="_p" /></td>
</tr>
</table>
<input type="text" id="username" size="20" maxlength="12" disabled>
<br>
<font size="1">If you checked "Replace Extended Network Logo" you MUST enter your name here so the Signature can be created. Otherwise your signature WILL NOT DISPLAY.<br><br>If you'd like to keep the Extended Network Logo LEAVE THE ABOVE FIELD BLANK!</font>
<hr>
<input type="button" value="Generate my Layout!" style="text-align: center;" onClick="make_sig()" onSubmit="make_sig()">
<div id="urlbox"></div>
</table>
<br>
</td>
</td>
</table>

 

I had a feeling you'd be the one who'd answer my cry!

 

Thank you very much. You're Member Title is well deserved! I'm not sure if you're thanked alot, but, from the browsing I've done around the site while waiting for my answer I see that you're one, if not the most, helpful people here! So thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.