Solved

Need some help with textfield, select menu and checkbox interaction.

Posted on 2010-09-08
7
389 Views
Last Modified: 2012-05-10
Everything is explained in the code window.

Thank you,

Brian
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>



<body>

<label>

		<input type="checkbox" name="checkbox" id="checkbox" />

</label>

If Checkbox is checked then the B field will automatically EQ the A field value and so on with C and D and E and F. Fields B, D and F will also be &quot;disabled&quot;. If the checkbox is unchecked then the values will remain the same but editable again.<br />

<br />

<br />

<table width="0" border="0" cellspacing="0" cellpadding="0">

		<tr>

				<td colspan="2"><label>

						A Field

										<input type="text" name="textfield" id="textfield" value="First Name" /> 

						B Field

				</label></td>

				<td width="155"><input type="text" name="textfield2" id="textfield2" /></td>

		</tr>

		<tr>

				<td colspan="2"><label> C Field

								<input type="text" name="textfield3" id="textfield3" value="First Name" />

						D Field </label></td>

				<td><input type="text" name="textfield3" id="textfield4" /></td>

		</tr>

		<tr>

				<td width="193">E Field 

						<label>

								<select name="select" id="select">

										<option value="1">A</option>

										<option value="2">B</option>

								</select>

				</label></td>

				<td width="118"> F Field</td>

				<td><select name="select2" id="select2">

						<option value="1">A</option>

						<option value="2">B</option>

				</select></td>

		</tr>

</table>



</body>

</html>

Open in new window

0
Comment
Question by:brihol44
7 Comments
 
LVL 5

Expert Comment

by:drakeshe
Comment Utility
Need more input please...
0
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
<<B field will automatically EQ the A field value >>
what does this means?
0
 
LVL 5

Expert Comment

by:drakeshe
Comment Utility
Are you familiar with javascript or jquery?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Accepted Solution

by:
ansudhindra earned 450 total points
Comment Utility
Hi, try th following code, let me know in case of ny thing neede....
test1.html
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 50 total points
Comment Utility
try this code as well (assuming EQ means Equal :))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
   function enableAndCopy(thisObj)
   {
      if ( thisObj.checked )
	  {
		document.getElementById("textfield2").disabled = true;
		document.getElementById("textfield2").value = document.getElementById("textfield1").value;
		document.getElementById("textfield4").disabled = true;
		document.getElementById("textfield2").disabled = document.getElementById("textfield3").value;
		document.getElementById("select2").disabled = true;
		document.getElementById("select2").value = document.getElementById("select1").value;
	  }
	  else
	  {
		document.getElementById("textfield2").disabled = false;
		document.getElementById("textfield4").disabled = false;
		document.getElementById("select2").disabled = false;
	  }
   }
</script>
</head>

<body>
<label>
		<input type="checkbox" name="checkbox" id="checkbox" onclick="enableAndCopy(this)"/>
</label>
If Checkbox is checked then the B field will automatically EQ the A field value and so on with C and D and E and F. Fields B, D and F will also be &quot;disabled&quot;. If the checkbox is unchecked then the values will remain the same but editable again.<br />
<br />
<br />
<table width="0" border="0" cellspacing="0" cellpadding="0">
		<tr>
				<td colspan="2"><label>
						A Field
										<input type="text" name="textfield" id="textfield" value="First Name" /> 
						B Field
				</label></td>
				<td width="155"><input type="text" name="textfield2" id="textfield2"  /></td>
		</tr>
		<tr>
				<td colspan="2"><label> C Field
								<input type="text" name="textfield3" id="textfield3" value="First Name" />
						D Field </label></td>
				<td><input type="text" name="textfield3" id="textfield4" /></td>
		</tr>
		<tr>
				<td width="193">E Field 
						<label>
								<select name="select" id="select">
										<option value="1">A</option>
										<option value="2">B</option>
								</select>
				</label></td>
				<td width="118"> F Field</td>
				<td><select name="select2" id="select2" >
						<option value="1">A</option>
						<option value="2">B</option>
				</select></td>
		</tr>
</table>

</body>
</html>

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
Sorry, small change
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Untitled Document</title>
	<script>
	   function enableAndCopy(thisObj)
	   {
		  if ( thisObj.checked )
		  {
			document.getElementById("textfield2").value = document.getElementById("textfield").value;
			document.getElementById("textfield2").disabled = true;
			document.getElementById("textfield4").value = document.getElementById("textfield3").value;
			document.getElementById("textfield4").disabled = true;
			document.getElementById("select2").value = document.getElementById("select1").value;
			document.getElementById("select2").disabled = true;
		  }
		  else
		  {
			document.getElementById("textfield2").disabled = false;
			document.getElementById("textfield4").disabled = false;
			document.getElementById("select2").disabled = false;
		  }
	   }
	</script>
	</head>

	<body>
	<label>
			<input type="checkbox" name="checkbox" id="checkbox" onclick="enableAndCopy(this)"/>
	</label>
	If Checkbox is checked then the B field will automatically EQ the A field value and so on with C and D and E and F. Fields B, D and F will also be &quot;disabled&quot;. If the checkbox is unchecked then the values will remain the same but editable again.<br />
	<br />
	<br />
	<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr>
					<td colspan="2"><label>
							A Field
											<input type="text" name="textfield" id="textfield" value="First Name" /> 
							B Field
					</label></td>
					<td width="155"><input type="text" name="textfield2" id="textfield2"  /></td>
			</tr>
			<tr>
					<td colspan="2"><label> C Field
									<input type="text" name="textfield3" id="textfield3" value="First Name" />
							D Field </label></td>
					<td><input type="text" name="textfield3" id="textfield4" /></td>
			</tr>
			<tr>
					<td width="193">E Field 
							<label>
									<select name="select" id="select">
											<option value="1">A</option>
											<option value="2">B</option>
									</select>
					</label></td>
					<td width="118"> F Field</td>
					<td><select name="select2" id="select2" >
							<option value="1">A</option>
							<option value="2">B</option>
					</select></td>
			</tr>
	</table>

	</body>
	</html>

Open in new window

0
 

Author Closing Comment

by:brihol44
Comment Utility
Perfect! Thanks ansudhindra! gurvinder372 the select menu wasn't working as the same as the other textfields... just FYI... but almost working correctly.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now