logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-29-2009, 11:44 AM   #1
swetha123
 
Join Date: Oct 2008
Posts: 17
Default Pass the Input text value in a TD cell using DOM

hello ,

I need to alert the value entered in the text box,which is in TD cell, using DOM

can any one tell how please
here is the code with out a text box which is working

Code:
 
<html>
<head>
<script type="text/javascript">
function cell()
{
var x=document.getElementById('myTable').rows[0].cells;
alert(x[0].innerHTML);
}
</script>
</head>
<body>
 
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br />
<input type="button" onclick="cell()" value="Alert first cell">
 
</body>
</html>
here is what i need
HTML Code:
 
<html>
<head>
<script type="text/javascript">
function cell()
{
var x=document.getElementById('myTable').rows[0].cells;
alert(x[1].firstChild.Value);
}
</script>
</head>
<body>
 
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td><input type="text" id="txt"></td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br />
<input type="button" onclick="cell()" value="Alert first cell">
 
</body>
</html>
but i can't see the output if anything wromg please tell me

thanks
Swetha

Last edited by davidj; 01-29-2009 at 02:27 PM..
swetha123 is offline   Reply With Quote
Old 01-29-2009, 12:31 PM   #2
swetha123
 
Join Date: Oct 2008
Posts: 17
Default pass the Text box value and the price value using DOM

hello

I need to alert the text what i entered in the text box and need to alert the price value which is to the side of the $ symbol

If remove the $ symbol and alert the price then i can see the Price
but i need the $ symbol there but in alert there is no need to pass the $ symbol only pass the price i.e 1000

here is my code

Code:
<html>
<head>
<script type="text/javascript">
function cell(i)
{
//var x=document.getElementById('myTable').rows[0].cells;
//alert(x[0].innerHTML);
var x=document.getElementById('myTable')
var y = x.rows[i].cells[1].firstChild.value;
var z = x.rows[i].cells[0].firstChild[getElementById(txt1).value];

alert(y);
alert(z);
}
</script>
</head>
<body>
<?php
$price=1000;
echo'<table id="myTable" border="1">';
for ($i=0; $i<3; $i++)
{
    echo'<tr>
         <td>$<input type="text" id="txt1" value="'.$price.'" disabled/></td>
         <td> <input type="text" id="txt"/></td>
         <td>  <input type="button" onClick="cell('.$i.')" value="Alert"></td>
         </tr>';
}
echo'</table>';
?>
</body>
</html>
swetha123 is offline   Reply With Quote
Old 01-29-2009, 02:26 PM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

can you not use a div as a place holder where you want the data to appear

HTML Code:
 
<!-- used in cell -->
 
<div id="data"></div>
 
Code:
 
document.getElementById("data").innerHTML = document.getElementById("textfield").value
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-29-2009, 02:30 PM   #4
domedia
Administrator
domedia's Avatar
 
Join Date: Dec 2003
Posts: 9,730
Default

You can use whatever, as long as it has an ID attribute, even a table cell.
domedia is offline   Reply With Quote
Old 01-29-2009, 02:44 PM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

yes true

but by inserting an placeholder which can be positioned within the TD i would asume you would have better positioning control
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-29-2009, 02:55 PM   #6
domedia
Administrator
domedia's Avatar
 
Join Date: Dec 2003
Posts: 9,730
Default

Table cells are usually pretty easy. You want the data in the grid to be aligned to left/right, style the text maybe, add some padding/margin to the box etc. Unless you're using tables for layout, in which case you're screwed anyways, you can simply use classes, right use of th/td etc to style regular data tables. I can see where you're coming from, but it's seems redundant.
domedia is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:47 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com