onclick function not returning parameters?

B

brianj7675

Basically i'm trying to write a previous next link in order to go to
the next page in my database(similar to google's with numbers in the
middle for pages the user wants to jump to.

My only thought is i'm losing the parameters on page reload.
But if that is the case then I don't know the correct technique to keep
the variables
I am programming in php but using a javscript function with onclick.
I could use $_SESSION variables to retain the values in the page but i
shouldn't have to do that should I?

Here is the code:

for ($i=0; $i <= $max_page_number; $i++)
{?>
<a href = 'http://localhost/local/restaurants.php'
onclick='nav(<?echo
$i.",".$max.",".$min.",".$page_results.",".$page_number;?>);'><?echo
$i;?>&nbsp;</a>
<?}

And Here is the function:
<script language = "JavaScript">
<!--

function nav(pointer, maxx, minn, page_results, page_number)
//sets the min and max limits
{
maxx= pointer * page_results;
minn= maxx - page_results;
page_number = pointer; //change page number
//document.writeln("Do you really want to follow this link?"+maxx+'::'+
minn+'::'+ page_results+'::'+ page_number);
}

//-->
</script>

As you can see i've commented out a document.writeln which displays the
variables on a web page and increments them accordingly.
but there is nothing else on the web page when i use it.

ANy help would be appreciated
b
 
T

Thomas 'PointedEars' Lahn

[...]
My only thought is i'm losing the parameters on page reload.

Of course. Global variables are properties of the global object, which
is recreated on reload as the client-side script engine is terminated prior.
But if that is the case then I don't know the correct technique to keep
the variables

Sessions which require server-side programming, such as
I am programming in php but using a javscript function with onclick. ^^^
I could use $_SESSION variables to retain the values in the page but i
shouldn't have to do that should I?

You should.
Here is the code:

for ($i=0; $i <= $max_page_number; $i++)
{?>
<a href = 'http://localhost/local/restaurants.php'
onclick='nav(<?echo
$i.",".$max.",".$min.",".$page_results.",".$page_number;?>);'><?echo
$i;?>&nbsp;</a>
<?}

Although I do understand PHP, other subscribers may not. We are not your
preprocessors, PHP is. So please use it and post what the client receives.
And Here is the function:
<script language = "JavaScript">
<!--

Should read

function nav(pointer, maxx, minn, page_results, page_number)
//sets the min and max limits
{
maxx= pointer * page_results;
minn= maxx - page_results;
page_number = pointer; //change page number
//document.writeln("Do you really want to follow this link?"+maxx+'::'+
minn+'::'+ page_results+'::'+ page_number);
}

I don't see page_number defined elsewhere, so I have to assume it is only
a local variable. JS does support call-by-value only, so if the local
execution context is left, nothing has changed in the global context.
//-->
</script>

That should read

As you can see i've commented out a document.writeln which displays the
variables on a web page and increments them accordingly.
but there is nothing else on the web page when i use it.

Unless the function is called when the document is loaded, you should not
use document.write(ln); it overwrites the content once the document has
loaded. In that case, you have to use methods introduced in the IE DOM
or W3C DOM Level 1.


PointedEars
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top