Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post

    make <p id""></p> apear in an input field

    I currently have this code
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>48897</title>
    	</head>
    	<body  onload="makeTotal();">
    		<form onsubmit="makeTotal();return false;">
    			<table>
    				<thead>
    					<tr>
    						<th width="144">Minutes</th>
    						<th width="144">Seconds</th>
    					    <th width="94">time so far </th>
    					</tr>
    				</thead>
    				<tbody>
    					<tr>
    						<td><input type="text" onblur="makeTotal()"></td>
    						<td><input type="text" onblur="makeTotal()"></td>
    					    <td><p id="result2">Default Value</p></td>
    					</tr>
    					<tr>
    						<td><input type="text" onblur="makeTotal()"></td>
    						<td><input type="text" onblur="makeTotal()"></td>
    					    <td><p id="result3">Default Value</p></td>
    					</tr>
    					<tr>
    						<td><input type="text" onblur="makeTotal()"></td>
    						<td><input type="text" onblur="makeTotal()"></td>
    					    <td><p id="result4">Default Value</p></td>
    					</tr>
    				</tbody>
    			</table>
    			
    		</form>
    
    		<p id="result">Default Value</p>
    
    		
    
    		<script type="text/javascript">
    
    
    			function makeTotal() 
                {  
    				var result = document.getElementById("result"); 
        
    	            var list = document.getElementsByTagName("form")[0].getElementsByTagName("table")[0].getElementsByTagName("input"); 
                    var total = 0; 
    
                    for(var i = 0,s=2; i < list.length;s++) 
                    { 
                    total += Number(list[i++].value) * 60 + Number(list[i++].value); 
                    var time = new Date(total * 1000); 
    
                    document.getElementById("result"+s).firstChild.nodeValue = time.getUTCHours() + ":" + time.getUTCMinutes() + ":" + time.getUTCSeconds(); 
                    } 
    
                    var time = new Date(total * 1000); 
                     result.firstChild.nodeValue = time.getUTCHours() + ":" + time.getUTCMinutes() + ":" + time.getUTCSeconds(); 
               } 
    
    		</script>
    		
    	</body>
    </html>
    Simply How would I make the
    <p id="resultn">Default Value</p>
    Lines appear in a input feild instead

    Thanks

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    All input text elements have a value attribute/property. Use that.

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post
    yeah I know I would use something like this
    Code:
     <input type="text" name="textfield" value="">
    although I dont know how to put the
    Code:
    <p id="result">Default Value </p>
    into the value=""

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Is this what you want?

    <input type="text" name="result1" id="result1" value="Default Value" />

    Then change this:

    document.getElementById("result"+s).firstChild.nodeValue = time.getUTCHours() + ":" + time.getUTCMinutes() + ":" + time.getUTCSeconds();

    to:

    document.getElementById("result"+s).value = time.getUTCHours() + ":" + time.getUTCMinutes() + ":" + time.getUTCSeconds();
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post
    thanks that worked


  •  

    Posting Permissions

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