I generated a dropdown list using a program I found on a website..
It turned out ok,,, but I have no idea what to do with it.
Yes I am a 77 year old geek, and I want to know how to create some
activity when someone clicks on a choice.. I would like to be able
to identify the users location while he pages through my site..
So if someone selects USA and then KANSAS how am I supposed to know
and create some action.. Perhaps set a cookie on so I will not continue
to ask where he/she is located. Here is what I have now..
And keep in mind, I generated this code, I have no idea what it is doing, I know the dropdown list works...
You need to add a "submit" button and then, with PHP, you will need to retreive the values that the user entered and from their you will be able to create your cookie.
If you do a quick google search about PHP forms you'll find easily some code to copy/paste; and same about how to create a cookie.
G Bonnet,
Thanks, but I don't think you realize that there are some of us who really
are Dummies.. I know at least one of them,,,,, ME...
I have no idea what a PHP is, or if I even have PHP on my computer.
I have enough trouble with JavaScript!!!
I Thank you since you are the only one who took time to answer.
As I said, I have no idea what PHP is, and in your response you said I
needed to add a "submit" button, not sure how or where this would go,
but I think you might be telling me that once the user selects a state,
I need to have another button asking him or her to submit..
As it stands you could copy and paste my code , then you will see
exactly what it does.
I am slightly familiar with cookie set/get since I learn by example and I have
seen some basic cookie code..
Thanks again,,
I would still welcome any advice other than suggesting I look up another
tutorial,, I have been through many, and each one only leaves me more
confused..
As you can see there is not much hope for me...
From your post i assume that you do not want to deal with server side programming but i will mention it briefly. If you submitted the user selection from the request you could get the value of his selection and use it on the backend. So, in a servlet or portlet for example your could do
Code:
String state =request.getParameter("idOfSelectBox");
and then you store it and use however you like. Since this is probably not the case, you could do something similar in javascript and use it while the user is on the same page (i mean without the page reloading from the browser cause you will loose the information)
In order to get the the value from the select box you would need a javascript function to handle it for storage and then use it. So in your selelctbox you need to put an onChange() event to catch any user selection and trigger your function. I would suggest that you dropped the ready-made code and write one yourself so that you understand what you are doing. So for a simple select box you start with:
HTML Code:
<select id="state" name="state"><option value="alabama">Alabama
<option value="newyork">New York
<option value="california">California
</select>
you then need to notify your page that the value has changed so your selectbox tag now looks like this:
this puts an onclick event that triggers the function showState(). This function gets the value stored previously in the variable state and presents it in an alert.
I think that now you understand how you can use this variable in other situations using javascript. You can use the variable itself or if you want to put the information in an other page element like an text input field you could do something like:
Bookmarks