Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write to a table cell...

Status
Not open for further replies.

jstar7

Programmer
Dec 17, 2002
61
GB
Hello there,

I have an input box and a button. I want to print the contents of the box to a table cell on the same page when the button is clicked.
Then I want to do the same thing again and again adding to the table cell each time the button is pressed.
Ive been trying the document.write thing but it just creates a new page.
Any one know how to do this?

Cheers,
Jonny
 
Hi jstar7
Try this:
Code:
<html>
<head>
<script>
function AddIt(){
	document.getElementById(&quot;theCell&quot;).innerHTML += document.getElementById(&quot;theTxt&quot;).value;
}
</script>
</head>
<body>
<input type=&quot;text&quot; id=&quot;theTxt&quot;><input type=&quot;button&quot; value=&quot;Add It&quot; onClick=&quot;AddIt()&quot;>
<table border=1>
<tr>
<td id=&quot;theCell&quot;>
</td>
</tr>
</table>
</body>
</html>
Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) &&(((parseIntx.toString()+y.toString())-x-y)%9)!=0)){alert(&quot;I'm a monkey's uncle&quot;);}
 
worked a treat mate!
cheers,
Jonny
 
this works great but it adds the next contents to the end of the string forcing the cell to expand horizontally.
Could it be changed to add a <br> somewhere at the end so as the new contents added starts on a new line?
 
Sure
Change the line in the AddIt function to this:
Code:
document.getElementById(&quot;theCell&quot;).innerHTML += document.getElementById(&quot;theTxt&quot;).value + &quot;<br>&quot;;
Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) &&(((parseIntx.toString()+y.toString())-x-y)%9)!=0)){alert(&quot;I'm a monkey's uncle&quot;);}
 
Hardly! But thanks, no probs.[bigsmile] Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) &&(((parseIntx.toString()+y.toString())-x-y)%9)!=0)){alert(&quot;I'm a monkey's uncle&quot;);}
 
ok one last thing....

I use function below to check the email is valid, then if it is, its printed in the cell. Now what I would like to do as well is to make the contents a new hidden input so i can pass it to the next page ASP style. So basically the user can input as many times as they like and each time a new line of code will be created with an incrementing count each time.

Ive tried something like this but it aint happenin...ya got any ideas?

<script language=&quot;JavaScript&quot;>
var count =0;

function checkEmail() {
var x = document.tellafriend.friend.value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
if (!(filter.test(x))) {
alert('Invalid Email Address. Please re-enter your email again!');
return false;
}
document.getElementById(&quot;listemail&quot;).innerHTML += document.getElementById(&quot;friend&quot;).value + &quot;<br>&quot;;
document.tellafriend (&quot;<input type=hidden name='friend&quot; + count + &quot;' value='&quot; + x + &quot;'>&quot;);
count = count+1;
}
</script>
 
Whilst I'm trying to do that, you can change this line
document.getElementById(&quot;listemail&quot;).innerHTML += document.getElementById(&quot;friend&quot;).value + &quot;<br>&quot;;

to
document.getElementById(&quot;listemail&quot;).innerHTML += x;

because you've already put it in the variable x. I didn't realise that when I first wrote that for you. Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) &&(((parseIntx.toString()+y.toString())-x-y)%9)!=0)){alert(&quot;I'm a monkey's uncle&quot;);}
 
OK, give this a go....
Code:
function checkEmail() {
var x = document.tellafriend.friend.value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/; 
if (!(filter.test(x))) {
alert('Invalid Email Address. Please re-enter your email again!');
return false;
}
document.getElementById(&quot;listemail&quot;).innerHTML += x + &quot;<br>&quot;;
var temp = document.createElement(&quot;input&quot;);
	temp.type=&quot;hidden&quot;;
	temp.id=&quot;friend&quot;+count;
	temp.value=x;
	document.getElementById(&quot;tellafriend&quot;).appendChild(temp);
count = count+1;
}
Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) &&(((parseIntx.toString()+y.toString())-x-y)%9)!=0)){alert(&quot;I'm a monkey's uncle&quot;);}
 
No probs, glad I could help. Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) &&(((parseIntx.toString()+y.toString())-x-y)%9)!=0)){alert(&quot;I'm a monkey's uncle&quot;);}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top