Click to See Complete Forum and Search --> : Change "Value" with each page load


THT
07-27-2005, 11:46 AM
I would think this script existed out there somewhere but I can't find it.
Here's the basics:

<input type="text" name="keyword" size="40" value="keyword1" />

I'm looking to have the value=".." field change with each page load.
It would need to draw from a list of keywords.

keyword1
keyword2
keyword3

etc....

Therefore, the next time the user loads the webpage it will look like this:
input type="text" name="keyword" size="40" value="keyword2" /

Then:

input type="text" name="keyword" size="40" value="keyword3" /

And so on...


Anyone know of a script for this?

Thanks

THT

zingmatter
07-27-2005, 12:16 PM
Using ASP:

<%
if session("keywordcount") = "" then
session("keywordcount") = "1"
else
session("keywordcount") = CStr(CInt(session("keywordcount")) + 1)
end if

%>

<input type="text" name="keyword" size="40" value="keyword<%= session("keywordcount") %>" />

I'm not sure if session variables can hold integer values (which case you can simply code session("keywordcount") = session("keywordcount") + 1 )

Hope this helps

THT
07-27-2005, 12:44 PM
Excuse my lack of ASP skills

Where will the keywords be stored? Let's say with each page load I want the following to rotate:

dog
cat
goat
horse
elephant

etc.....

Thanks

zingmatter
07-27-2005, 12:56 PM
It depends how many there are. If there are just a handful then you could place them on the same page, prehaps in an array:

keyword_array = array("cat","dog","horse","elephant")

keyword = keyword_array(CInt(session("keywordcount")))


Alternatively, you could keep the keywords in a text file on the server, or even in a database.

THT
07-27-2005, 01:01 PM
Thanks, there will be about 20 keywords

So given this info how would the entire code be written in full?

Lunch on me if I ever make it to Scotland!

zingmatter
07-27-2005, 01:09 PM
<%
Dim keyword

'//if we assume 20 keywords (the array index will go from 0 to 19)

if session("keywordcount") = "" then
session("keywordcount") = "0"
else
if CInt(session("keywordcount")) < 20 then
session("keywordcount") = CStr(CInt(session("keywordcount")) + 1)
else
'//go back to the start
session("keywordcount") = "0"
end if


keyword_array = array("cat","dog","horse","elephant")

keyword = keyword_array(CInt(session("keywordcount")))

%>

<input type="text" name="keyword" size="40" value="<%= keyword %>" />

There may be an issue with data types that you'll have to play with but I think this'll work.

Good luck
:)

THT
07-27-2005, 02:15 PM
Microsoft VBScript compilation error '800a03f6'

Expected 'End'

/info/test.asp, line 23

zingmatter
07-27-2005, 02:22 PM
Woops!


<%
Dim keyword

'//if we assume 20 keywords (the array index will go from 0 to 19)

if session("keywordcount") = "" then
session("keywordcount") = "0"
else
if CInt(session("keywordcount")) < 20 then
session("keywordcount") = CStr(CInt(session("keywordcount")) + 1)
else
'//go back to the start
session("keywordcount") = "0"
end if
end if


keyword_array = array("cat","dog","horse","elephant")

keyword = keyword_array(CInt(session("keywordcount")))

%>

<input type="text" name="keyword" size="40" value="<%= keyword %>" />


Try this

THT
07-27-2005, 02:55 PM
So far so good! I'll keep you posted!

Many thanks

THT
07-27-2005, 06:24 PM
Thanks again.

This script helped me greatly. Chances are I will probably be coming back to post regarding more scripts I need help with.

I would like to "give back" and support this forum or it's users in some way. Is there an area where you can become a "Premium Member"? Any other suggestions?

No, I'm not rich!

:)



THT