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

named anchor problem

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
Ok, I've had this post over on the html forum trying to get through it and, although they have been great, I can't get this to work. I thought it was an html problem, but I'm going to see if the php people can help.

I've got a page with 4 'Calculate' buttons derived from a function:
Code:
<?
function calculate($x){
  echo "<a href=\"#calc$x\";
  echo "<input type=\"submit\" name=\"submit\" value=\"Calculate\"></a>;
}
?>

I'm trying to get the page, upon reloading itself, to go back to the original position of the 'Calculate' button that was pressed. It reloads b/c I have quite a few calculations that are activated using data that is entered into a form. My reason is that the form is long and I'm trying to prevent the user from scrolling from the top after every reload. At the point of the 'Calculate' button I code:
Code:
<a name="calc1"></a><? calculate(1); ?>

..stuff

<a name="calc2"></a><? calculate(2); ?>
This code works well in Firefox, but not in IE6,7. My target audience only has IE6, so the fact that if works in Firefox is irrelevent besides the fact that it is driving me crazy wondering why it works in one and not the other.

This problem is more a matter if irritation for me now than having to make it work. I just have to know why! Can someone take a look and see if my php needs to be altered? I even tried to use $_GET from my input:
Code:
echo "<form method=\"post\" action=\"$SERVER['PHP_SELF']\">";
by putting '&nav=#calc1' but could not get that to work either. Any php person have an idea? Thanks.
 
does this not work?

Code:
echo "<form method=\"post\" action=\"$[red]_[/red]SERVER['PHP_SELF'][red]#calc1[/red]\">";
 
Thanks, yes it does, but I have 4 positions of 'Calculate'. I tried to set $m="#calc$x" within the function, then use $_Server['PHP_SELF']."$m" but can't get the variable to carry over to the browser once it reloads.

With my current code, when I highlight 'Calculate' in FF, I get the whole link including #calc1, or 2, or 3 in the status bar at the bottom. In IE, I only get the link to the current page without the #calc1.

I just need to get the variable to pass through upon reload, but I'm having trouble with where to put the code.

Thanks again
 
ok, scratch that about the code executing. On clicking 'Calculate' with my current setup, the calculations DO NOT execute, the page just scrolls. Got to come up with something different. Sorry. Tried so many things, I'm breaking other things to make this work.
 
the handling of named anchors is up to the browser. not all browsers handle things the same way and it is nigh on impossible to control the behaviour from the server side.

I'd guess the best solution for your usability issues is to use ajax to send the data and handle the result. then the form need not scroll at all.

if that is not ok then a little bit of javascript in the code could scroll the window for you. you would need to pass in the value of the anchor using php so that the js code would know where to scroll to. hide the anchor in a hidden field within the form

something like this
Code:
<script language='JavaScript'>
<!--
window.onload = function () {
window.location.href='#<?=$_POST['anchor']?>';};
//--></script>
 
I would consider using divs or spans and doing like so:
function showCalc(calcID)
{
document.getElementById("calcID").style.visibility='visible';
</script>

Of course, you would have to do a loop and disable visibility of the others..

Or.. You might instead of doing this, just set the "active calc" to a static position above the others? Many ways to solve this...


Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top