SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    textfields help.

    hey guys, ive manage to come up w/ these...
    icant figure out though why linebreak doesnt work if i use input boxes, but if i use texarea it works fine, plus can you also help me out by adding a selection box to the equation?

    Code:
    <script type="text/javascript">
    var desc = new Array();
    desc['a1'] = 'First name';
    desc['a2'] = 'Last name';
    desc['a3'] = 'Address';
    desc['a4'] = 'Zip';
    desc['a5'] = 'City';
    desc['a6'] = 'Country';
    
    function CopyFields(){
        var copytext = '';
        for(var i = 0; i < arguments.length; i++){
            copytext += desc[arguments[i]] + ': ' + document.getElementById(arguments[i]).value + '\n';
        }
        var tempstore = document.getElementById(arguments[0]).value;
        document.getElementById(arguments[0]).value = copytext;
        document.getElementById(arguments[0]).focus();
        document.getElementById(arguments[0]).select();
        document.execCommand('Copy');
        document.getElementById(arguments[0]).value = tempstore;
    }
    --></script>	</head>
    	<body>
    		<p>
    			<input id="a1"></br>
    			<input id="a2"></br>
    			<input id="a3"></br>
    			<input id="a4"></br>
    			<input id="a5"></br>
    			<input id="a6"></br>
    			<br />
    			<input type="button" value="Copy" onclick="CopyFields('a1', 'a2', 'a3', 'a4', 'a5', 'a6');"> </p>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's the point of having different things - text inputs are for single lines whereas textareas are for larger blocks of text that may include linebreaks. If text inputs allowed linebreaks, they'd just be textareas that are one line tall.

    plus can you also help me out by adding a selection box to the equation?
    Read that again. Now look at your code. What exactly do you want? It's impossible to tell because you haven't bothered to explain properly.

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, sorry i didnt clarify.

    came up with these, problem is that i cant copy what i selected from the dropdown menu and the reset button doesnt work. can i get help?

    thanks guys!

    Code:
    <html>
    	<head>
    		<title></title>
    	</head>
    
    <script type="text/javascript">
    var desc = new Array();
    desc['a1'] = 'issue';
    desc['a2'] = 'tel';
    desc['a3'] = 'account name';
    desc['a4'] = 'caller';
    desc['a5'] = 'OS';
    desc['a6'] = 'modem';
    desc['a7'] = 'router';
    
    function CopyFields(){
        var copytext = '';
        for(var i = 0; i < arguments.length; i++){
            copytext += desc[arguments[i]] + ': ' + document.getElementById(arguments[i]).value + '\n';
        }
        var tempstore = document.getElementById(arguments[0]).value;
        document.getElementById(arguments[0]).value = copytext;
        document.getElementById(arguments[0]).focus();
        document.getElementById(arguments[0]).select();
        document.execCommand('Copy');
        document.getElementById(arguments[0]).value = tempstore;
    }
    --></script>
    
    
    
    	<body>
    		<table border="0" cellpadding="0" cellspacing="0" style="width: 500px">
    			<tbody>
    				<tr>
    					<td>
    						<table border="0" cellpadding="0" cellspacing="0" style="width: 500px">
    							<tbody>
    								<tr>
    									<td style="text-align: right">
    										issue:</td>
    									<td>
    										<textarea id="a1"></textarea></td>
    								</tr>
    								<tr>
    									<td style="text-align: right">
    										tel:</td>
    									<td>
    										<input id="a2" /></td>
    								</tr>
    								<tr>
    									<td style="text-align: right">
    										account name:</td>
    									<td>
    										<input id="a3" /></td>
    								</tr>
    								<tr>
    									<td style="text-align: right">
    										caller:</td>
    									<td>
    										<input id="a4" /></td>
    								</tr>
    								<tr>
    									<td style="text-align: right">
    										os:</td>
    									<td>
    										<select id="a5"><option selected="selected" value="">Windows 7</option><option value="">Windows Vista</option><option value="">Windows XP</option><option value="">X MAC 10.x</option><option value="">Other</option></select></td>
    								</tr>
    								<tr>
    									<td style="text-align: right">
    										modem:</td>
    									<td>
    										<input id="a6" /></td>
    								</tr>
    								<tr>
    									<td style="text-align: right">
    										router:</td>
    									<td>
    										<input id="a7" /></td>
    								</tr>
    							</tbody>
    						</table>
    						<input type="button" value="Copy" onclick="CopyFields('a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7');"> <input type="reset"></td>
    				</tr>
    			</tbody>
    		</table>
    	</body>
    </html>

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Most web browsers are not allowed to copy or paste to the clipboard, for security.
    I suggest that you have a separate text areas somewhere for collated data, so that you can copy the fields to there, and manually copy from there.

    The reset button only works when it and the fields are inside a form.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •