1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

concatenate string

Discussion in 'JavaScript' started by darkmunk, Oct 20, 2007.

  1. #1
    I am trying to put the value of a checkbox into a text field or remove it if it is unchecked, the code below is heavily commented because I am trying to work down thru it to find the error -
    <input name="CD" type="checkbox" id="CD" value="CD" onMouseUp="keyPoints('CD')">
    <input name="CC" type="checkbox" id="CC" value="CC">
    <input name="L" type="checkbox" id="L" value="L">
    <input name="AC" type="checkbox" id="AC" value="AC">
    
    <input name="keyPoints" type="text" value="">
    
    <script language="JavaScript" type="text/JavaScript">
    function keyPoints(thisCheckbox){
    	alert(thisCheckbox);
    	//str = document.frmSend.keyPoints.value;
    	//alert(str);
    	//if (str(indexOf(thisCheckbox))<0){
    		//alert("enpty");
    		//str = str + thisCheckbox;
    	//}
    }
    </script>
    Code (markup):
    Any thoughts?
     
    darkmunk, Oct 20, 2007 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Any Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    
    	function toggleKeys(nBox){
    
    		var nKeys = document.forms[0]['keyPoints'];
    		nBox.checked ? nKeys.value += nBox.value + " " : nKeys.value = nKeys.value.replace(nBox.value, "");
    		nKeys.value = nKeys.value.replace(/^\s+/,"").replace(/\s{2,}/g," ");
    	}
    	
    </script>
    <style type="text/css">
    
    	 body {background-color:#eae3c6;margin-top:60px}
    	 form {width:620px;margin:auto;font-family:times;font-size:12pt}
    	 fieldset {width:610px;background-color:#f0fff0;border:1px solid #87ceeb}
    	 legend {font-family:times;font-size:14pt;color:#00008b;background-color:#87ceeb;padding-left:3px;padding-right:3px;margin-bottom:5px}
    	 label {display: block}
    	.submitBtn {font-family:tahoma;font-size:10pt;display:block;margin-left:auto;margin-right:auto;margin-top:5px;margin-bottom:5px}
    
    </style>
    </head>
    	<body>
    		<form action="">
    		   <fieldset>
    			<legend>Form</legend>
    
    				<label>CD: <input type="checkbox" name="CD" value="CD" onclick="toggleKeys(this)"></label>
    				<label>CC: <input type="checkbox" name="CC" value="CC" onclick="toggleKeys(this)"></label>
    				<label>L:  <input type="checkbox" name="L"  value="L" onclick="toggleKeys(this)"></label>
    				<label>AC: <input type="checkbox" name="AC" value="AC" onclick="toggleKeys(this)"></label>
    
    				<label>Key Points: <input type="text" name="keyPoints" size="10" readonly></label>
    
    				<input type='submit' name='submit' value="Submit" class='submitBtn'>
    		   </fieldset>
    		</form>
    	</body>
    </html>
    
    Code (markup):
     
    Mike H., Oct 20, 2007 IP
  3. darkmunk

    darkmunk Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Excelent, thanks Mike, works a treat.:)
     
    darkmunk, Oct 20, 2007 IP