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!

asp variables into javascript

Status
Not open for further replies.

storm1976

Programmer
Jul 6, 2001
31
GB
hello there,

i worked out how to do the paging through recordset (finally just had some code in the wrong place, sorry james)

but now i would like to have a text box to so the punters can insert a page number and the jump to it. problem is how would i get the asp variables of the first page and the last page to create a range to validate in javascript?

i have the last page variable already which is needed to page through the recordset just a case of putting them into javascript to validate the number

cheers in advance
Storm
 
<%
firstPage = 1
lastPage = 15
%>

<script>
//you'd use quotes around values for strings....
jsFirstPage = <%=fistPage%>
jsLastPage = <%=lastPage%>
.....
</script> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
cheers mwolf00, but how would i use them in a javascript function new to all this sort of thing :eek:s

cheers
Storm
 
Now you'd use them like any other javascript variable. To validate the range use this (Not sure about the php page call - don't use php)...


<script>
function goThere(){
thisPage = document.myForm.goToPage.value
start = <%=firstPage%>
finish = <%=lastPage%>
isGood = true
if (isNaN(thisPage)){
isGood = false
}
else{
thisPage = parseInt(thisPage)
if (thisPage > finish || thisPage < start){
isGood = false
}
}
if (!isGood){
alert(&quot;Please enter a valid number between &quot; + start + &quot; and &quot; + finish)
}
else{
document.location = &quot;getPage.php?page=&quot; + thisPage
}
}
</script>

<form name=&quot;myForm&quot;>
<input name=&quot;goToPage&quot;>
<input type=button onClick=&quot;goThere()&quot; value=&quot;Get Page&quot;>
</form> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
no worries i dont use php either ;o)

righty i used the above code and it works alrighty apart from when i replace

document.location = &quot;getPage.php?page=&quot; + thisPage

with my page. i have a long querystring which needs to be added onto this.

document.location = &quot;searchresults.asp?&quot; + query + &quot;&ipag=&quot; + thispage

the query is a variable but doesnt seem to work correctly here.

cheers again
storm





 
if &quot;query&quot; is an asp variable you'd say...

document.location = &quot;searchresults.asp?<%=server.urlencode(query)%>&ipag=&quot; + thispage


not sure about php server-side code...
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
cheers mwolf00, will definitely keep that in mind :eek:)

worked a treat (but for some reason only when i took away the server.urlencode :eek:s)

or maybe thats some other problem in my code

cheers anyway
Storm

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top