Java Script problem Help me

V

Vinikz

Hi,
I am new to javascript. I did one program for fetch table row values
to text box. But i can fetch only first row . Here iam attaching
my code. Please help me.....

<html>
<head>
<script>
function swap(){

document.getElementById('s2').value=document.getElementById('text1').innerHTML;
document.getElementById('s3').value=
document.getElementById('text2').innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="radio" onClick="swap()">
<a id="text1" name="text1" >sunil</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text2" name="text2" >dibhu</a></td>
</tr>
<tr>
<td>
<input type="radio" onClick="swap()">
<a id="text1" name="text1" >shijin</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text2" name="text2" >vneeth</a>
</td>
</tr>
<tr>
<td>
<input type="text" id="s2" name="s2" >
</td>
<td>
<input type="text" id="s3" name="s3" >
</td>
</tr>
</table>
</body>
</html>
 
P

Peroli

Hi,
your <a> tag's id must be unique in your document. I see that you
have same id (text1 text2) for 2 different elements. Fix it, and it
will solve your issue.

-- Peroli Sivaprakasam
 
H

Herbert Blenner

Hi,
I am new to javascript. I did one program for fetch table row values
to text box. But i can fetch only first row . Here iam attaching
my code. Please help me.....

<html>
<head>
<script>
function swap(){

document.getElementById('s2').value=document.getElementById('text1').innerH-TML;
document.getElementById('s3').value=
document.getElementById('text2').innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="radio" onClick="swap()">
<a id="text1" name="text1" >sunil</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text2" name="text2" >dibhu</a></td>
</tr>
<tr>
<td>
<input type="radio" onClick="swap()">
<a id="text1" name="text1" >shijin</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text2" name="text2" >vneeth</a>
</td>
</tr>
<tr>
<td>
<input type="text" id="s2" name="s2" >
</td>
<td>
<input type="text" id="s3" name="s3" >
</td>
</tr>
</table>
</body>
</html>

Try the following code.

<html>
<head>
<script>
function swap(first,second)
{
document.getElementById('s2').value=document.getElementById(first).innerHTML;
document.getElementById('s3').value=document.getElementById(second).innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="radio" onClick="swap('text1','text2')">
<a id="text1">sunil</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text2">dibhu</a></td>
</tr>
<tr>
<td>
<input type="radio" onClick="swap('text3','text4')">
<a id="text3">shijin</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text4">vneeth</a>
</td>
</tr>
<tr>
<td>
<input type="text" id="s2">
</td>
<td>
<input type="text" id="s3">
</td>
</tr>
</table>
</body>
</html>

Good luck.

Herbert
 
V

Vinikz

Hi,
your <a> tag's id must be unique in your document. I see that you
have same id (text1 text2) for 2 different elements. Fix it, and it
will solve your issue.

-- Peroli Sivaprakasam

hi
thanks for ur reply.
can u give me any sample code for this issue. I think i need to use a
loop here for changing the <a> tag id. please help me.
 
V

Vinikz

Try the following code.

<html>
<head>
<script>
function swap(first,second)
{
document.getElementById('s2').value=document.getElementById(first).innerHTML;
document.getElementById('s3').value=document.getElementById(second).innerHTML;}

</script>
</head>
<body>
<table>
<tr>
<td>
<input type="radio" onClick="swap('text1','text2')">
<a id="text1">sunil</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text2">dibhu</a></td>
</tr>
<tr>
<td>
<input type="radio" onClick="swap('text3','text4')">
<a id="text3">shijin</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a id="text4">vneeth</a>
</td>
</tr>
<tr>
<td>
<input type="text" id="s2">
</td>
<td>
<input type="text" id="s3">
</td>
</tr>
</table>
</body>
</html>

Good luck.

Herbert


Hi Herbert,
Thanks for your reply. Its working now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top