...

View Full Version : make <p id""></p> apear in an input field



tsclan
12-16-2004, 10:45 PM
I currently have this 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

hemebond
12-17-2004, 12:28 AM
All input text elements have a value attribute/property. Use that.

tsclan
12-17-2004, 01:32 AM
yeah I know I would use something like this


<input type="text" name="textfield" value="">

although I dont know how to put the


<p id="result">Default Value </p>

into the value=""

glenngv
12-17-2004, 02:11 AM
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();

tsclan
12-17-2004, 08:34 AM
thanks that worked



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum