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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making onclick perform two functions -- possible? 1

Status
Not open for further replies.

jhherring

Programmer
Jun 18, 2002
33
US
Hello again. Yet another weird problem. Can some kind soul show me the right approach?

I have a form in one frame, and links in a nav frame that allow the user to scroll to specific points within the form. These links are defined as hotspots within an image map in the nav frame. So far, thanks to help from experts in this forum, everything is cool with the navigation -- when you click on link #3 in the nav frame, the form in the other frame scrolls to section #3. When you click on link #5 in the nav frame, the form in the other frame scrolls to section #5. Perfect in every way.

NOW, however, management wants something new (of course).

The form also has a JavaScript in it (below) that places the focus within the first text field when the whole form document loads.

<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
<!-- Begin
function toForm() {
document.form_name.first_field_name.focus();
}
// End -->
</script>


<body onload=&quot;toForm()&quot;>

This is nifty, but management now wants to improve the form so that the same effect happens within each SECTION of the form -- when you click on link #2, for instance, the form is now supposed to scroll to section #2 AND place the focus on the first form field within that section. Same logic if the user then clicks on link #4, and so on.

Since the onclick event handler is already &quot;occupied&quot; with the code to scroll to the appropriate point in the form (see below), how can I get it to do something else at the same time?


<AREA SHAPE=&quot;poly&quot; ALT=&quot;label&quot; COORDS=&quot;144,11,254,11,270,27,130,27&quot; HREF=&quot;body-frame.html#section-2&quot; onMouseOver=&quot;rollover(2)&quot; onMouseOut=&quot;original()&quot; onClick=&quot;setCurrent(2);&quot; target=&quot;body-frame&quot;>

(You can just ignore the references to the other JavaScript functions -- they're just simple rollover functions and they work fine.)

I've tried adding this:

document.form_name.second_field_name.focus();

after the current statement in the onclick, but here's the catch -- even if this would otherwise work, remember that the placing of the focus needs to take place in a different frame. Therefore, the reference to &quot;document&quot; (meaning the current document) won't work -- it's the wrong document. Can I reference the form document from within the nav frame? If so, how?

Lost and confused, as usual. Grateful for any suggestions, as usual.

John Herring
jhherring@yahoo.com
 

Well, that was very fast, and very helpful! Thanks! I now understand better how to address the document in the other frame, thanks to the clear syntax of your reply.

HOWEVER, it doesn't work as advertised. If I've copied-and-pasted correctly, there's some kind of problem remaining. Your code doesn't appear to place the focus in the correct field. Maybe I copied it wrong?

<pause while I tear my remaining hair out>

This is what I'm using now:

<AREA SHAPE=&quot;poly&quot; ALT=&quot;label&quot; COORDS=&quot;272,11,382,11,398,27,258,27&quot; HREF=&quot;body-frame.html#section3&quot; onMouseOver=&quot;rollover(3)&quot; onMouseOut=&quot;original()&quot; onClick=&quot;setCurrent(3);parent.body_frame.document.main_form.second_field_name.focus();&quot; target=&quot;body_frame&quot;>

Doubtless I've done something wrong, but I don't see what. Any suggestions?

Grateful for any help.

John Herring
jhherring@yahoo.com

 
ok, try...

<AREA SHAPE=&quot;poly&quot; ALT=&quot;label&quot; COORDS=&quot;272,11,382,11,398,27,258,27&quot; HREF=&quot;#&quot; onMouseOver=&quot;rollover(3)&quot; onMouseOut=&quot;original()&quot; onClick=&quot;setCurrent(3);parent.body_frame.location.href='body-frame.html#section3';parent.body_frame.document.main_form.second_field_name.focus();return false&quot;>
 
Wow! This code is more complex, but I gladly agree that it seems to do the job. Thanks! Problem seems to be solved.

The help you get in these forums is first-class!

John Herring
jhherring@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top