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

Fixing Javascript Buttons

Status
Not open for further replies.

bberrios

Programmer
Jun 18, 2002
18
US
I have this code for my buttons:

<FORM ACTION=&quot;ReportData_test2.asp&quot; METHOD=&quot;POST&quot; NAME=&quot;RW&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;PageNo&quot; VALUE=&quot;1&quot;>
<FONT FACE=&quot;Verdana, Arial, Helvetica, Sans Serif&quot; SIZE=&quot;2&quot;>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot; First Page &quot; ONCLICK=&quot;ShowFirstPage()&quot;>&nbsp;
<INPUT TYPE=&quot;submit&quot; VALUE=&quot; Prev Page &quot; ONCLICK=&quot;ShowPrevPage()&quot;>&nbsp;
<INPUT TYPE=&quot;submit&quot; VALUE=&quot; Next Page &quot; ONCLICK=&quot;ShowNextPage()&quot;>&nbsp;
<INPUT TYPE=&quot;submit&quot; VALUE=&quot; Last Page &quot; ONCLICK=&quot;ShowLastPage()&quot;>&nbsp;<BR>
</FONT>
</FORM>


The each need to go to the next page of a search result. Here is the scripting that goes with it...I know I am missing something, but I can't pinpoint it.

<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>
<!--
function ShowFirstPage() {
ShowPage(1);
}
function ShowPrevPage() {
var v = document.RW.PageNo.value;
if(v>1)
ShowPage(--v);
else
ShowPage(1);

}
function ShowNextPage() {
var v = document.RW.PageNo.value;
if(v<<%= lngPage %>)
ShowPage(++v);
else
ShowPage(<%= lngPage %>);
}
function ShowLastPage() {
ShowPage(<%= lngPage %>);
}
function ShowPage(p) {
var oldp = document.RW.PageNo.value;
if(document.all) {
document.all['pg'+oldp].style.visibility = 'hidden';
document.all['pg'+p].style.visibility = 'visible';
}
if(document.layers) {
document.layers['pg'+oldp].visibility = 'hide';
document.layers['pg'+p].visibility = 'show';
}

document.RW.PageNo.value = p;
}


document.RW.PageNo.value = 1;

//-->
</SCRIPT>
bb
 
Hi ...
when you use a submit input, you don't have any control on it's onclick event and when you click on it, it automaticly submits the form.
the only way is to use unsubmit event of the form which is useless here...
so you have to use simple button input and then in the javascript which you call, submit the form... so the code must be something like this :
<FORM ACTION=&quot;ReportData_test2.asp&quot; METHOD=&quot;POST&quot; NAME=&quot;RW&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;PageNo&quot; VALUE=&quot;1&quot;>
<FONT FACE=&quot;Verdana, Arial, Helvetica, Sans Serif&quot; SIZE=&quot;2&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot; First Page &quot; ONCLICK=&quot;ShowFirstPage()&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot; Prev Page &quot; ONCLICK=&quot;ShowPrevPage()&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot; Next Page &quot; ONCLICK=&quot;ShowNextPage()&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot; Last Page &quot; ONCLICK=&quot;ShowLastPage()&quot;> <BR>
</FONT>
</FORM>


<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>
<!--
function ShowFirstPage() {
ShowPage(1);
}
function ShowPrevPage() {
var v = document.RW.PageNo.value;
if(v>1)
ShowPage(--v);
else
ShowPage(1);

}
function ShowNextPage() {
var v = document.RW.PageNo.value;
if(v<<%= lngPage %>)
ShowPage(++v);
else
ShowPage(<%= lngPage %>);
}
function ShowLastPage() {
ShowPage(<%= lngPage %>);
}
function ShowPage(p) {
var oldp = document.RW.PageNo.value;
if(document.all) {
document.all['pg'+oldp].style.visibility = 'hidden';
document.all['pg'+p].style.visibility = 'visible';
}
if(document.layers) {
document.layers['pg'+oldp].visibility = 'hide';
document.layers['pg'+p].visibility = 'show';
}

document.RW.PageNo.value = p;
document.RW.submit() ;
}


document.RW.PageNo.value = 1;

//-->
</SCRIPT>

----
TNX.
E.T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top