User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 455,979 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,786 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 820 | Replies: 2
Reply
Join Date: Nov 2007
Posts: 7
Reputation: vinithktp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vinithktp vinithktp is offline Offline
Newbie Poster

Help Javascript Problem help me

  #1  
Nov 28th, 2007
Hi,
Im new to javaScript. Im trying to fetch data from html table row to text box by clicking radio button. But i can fetch only the first row. Here iam attaching my code...

JSP Code

<table>
<tr>
<td>Select</td>
<td>ID</td>
<td>FIRST NAME</td>
<td>LAST NAME</td>
<td>AGE</td>
<td>HOME TOWN</td>
<td>JOB</td>

</tr>
<% while( rs.next() ){%>
<tr><td><input type="radio" onClick="swap()"></div></td>
<td><a id="text1" name="text1" ><%=rs.getInt("id")%></a></td>
<td><a id="text2" name="text1" ><%=rs.getString("firstname")%></a></td>
<td><a id="text3" name="text1" ><%=rs.getString("lastname")%></a></td>
<td><a id="text4" name="text1" ><%=rs.getString("age")%></a></td>
<td><a id="text5" name="text1" ><%=rs.getString("hometown")%></a></td>
<td><a id="text6" name="text1" ><%=rs.getString("job")%></a></td>
</tr>
<%}%>
</table>


Javascript Function

<script>
function swap(){

document.getElementById('id').value=document.getElementById('text1').innerHTML;
document.getElementById('first_name').value= document.getElementById('text2').innerHTML;
document.getElementById('last_name').value=document.getElementById('text3').innerHTML;
document.getElementById('age').value= document.getElementById('text4').innerHTML;
document.getElementById('home_town').value=document.getElementById('text5').innerHTML;
document.getElementById('job').value= document.getElementById('text6').innerHTML;
}
</script>

HTML form

<form id="form1" name="form1" method="post" action="">
<table width="353" border="1">
<tr>
<td width="193">ID</td>
<td width="144"><label>
<input name="id" type="text" id="id" />
</label></td>
</tr>
<tr>
<td>FIRST NAME </td>
<td><label>
<input name="first_name" type="text" id="first_name" />
</label></td>
</tr>
<tr>
<td>LAST NAME </td>
<td><label>
<input name="last_name" type="text" id="last_name" />
</label></td>
</tr>
<tr>
<td>AGE</td>
<td><label>
<input name="age" type="text" id="age" />
</label></td>
</tr>
<tr>
<td>HOME TOWN </td>
<td><label>
<input name="home_town" type="text" id="home_town" />
</label></td>
</tr>
<tr>
<td>JOB</td>
<td><label>
<input name="job" type="text" id="job" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="Submit" />
</div>
</label></td>
</tr>
</table>
</form>

I THINK HERE I NEED TO GIVE THE <A> TAG ID DYNAMICALLY. BUT I DONT KNOW HOW TO DO THAT. ANY ONE PLEASE HELP ME.

THANKING YOU,
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,604
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 119
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Javascript Problem help me

  #2  
Dec 1st, 2007
JS can't make any sense of the stuff inside the % while tag, because:

- It is dynamically created at runtime, but not by JS.

- You have multiple occurrences of the same id as the while repeats. This is not allowed.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Nov 2007
Posts: 7
Reputation: vinithktp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vinithktp vinithktp is offline Offline
Newbie Poster

Re: Javascript Problem help me

  #3  
Dec 1st, 2007
Hi MidiMagic
thanks you.
i will try to solve this with jsp code.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC