• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javascript function not sure how it works

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this fuction in my code that when u select a row in a table it will fire up a new page and pass it a ID selected from the first column.

Well I think that is what it does. the problem is that i cant get it to work.

The function is :

function selectItem(name)
{
ret=document.getElementById("btnSubmit");
document.all.rowId.value = name.parentElement.childNodes[0].innerText;
ret.click();
}
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry browser went a bit funny and posted before I had finished:

I have a form
<FORM action="displayRow.jsp" method="post">
<INPUT type="hidden" id="rowId" name="rowId">

this is the column its selecting
<!-- ROW ID -->
<TD class="tdNormal" on_Click="selectItem(this)" on_Mouse_Over="showHighlight(this)" on_Mouse_Out="clearHighlight(<%=tableRow%> "><%=rs.getInt(1)%></TD>

and in the other page I have the code

String RowID = request.getParameter("rowId");

which is returning null.

I have no experience of javascript, I would welcome any help in explianing line by line how the function works and is there a way to debug the statement to see what the ret object contains after it has been set.

Thanks for any help.

Tony
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wrote this real quick, I think it should be cross-browser compatiable, but I have not checked my code on any browser....

Eric



Eric
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric,

I will give that a try as well, but I have managed to put a fix in, by directly passing the rowID in, instead of the whole row :


<TD class="tdNormal" on_Click="selectItem(<%=rs.getInt(1)%> " on_Mouse_Over="showHighlight(this)" on_Mouse_Out="clearHighlight(<%=tableRow%> "><%=rs.getInt(1)%></TD>

and then amending the function so:

function selectItem(rowID)
{
ret=document.getElementById("btnSubmit");
document.all.rowId.value = rowID;
ret.click();
}

Thanks again Tony
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still have some problems if you want people to use this in other browsers

IE only supports document.all
need to use
document.getElementById
or
document.forms[0]

another thing...the click(); needs to be changed
to submit the form you should use
document.forms[0].submit();

Eric
reply
    Bookmark Topic Watch Topic
  • New Topic