Solved

keep value on form refresh

Posted on 2001-07-16
2
356 Views
Last Modified: 2008-03-04
I have a label and a list box (select) on a form.  Depending on the value of the list box the label is
displayed accordingly.  My problem is when there is
a 'refresh' (user comes back from another page or just
hits refresh button), the selected val. in list box is
ok, but the label is back to its initial value.

How can I resolve this problem?

I tried using an onload event with, but it gives me an error when accessing the list box object.

Any help is appreciated.
0
Comment
Question by:ocean9
2 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 85 total points
ID: 6288310
try this:


<html>
<head>
     <title>Untitled</title>
<SCRIPT>
function handlechange()
{

v=document.forms[0].elements['sel'].options[document.forms[0].elements['sel'].options.selectedIndex].value
for(i=1;i<=document.forms[0].elements['sel'].options.length;i++)
{
if(i!=v){
document.getElementById('label_' + i).style.visibility='hidden'
}
}
document.getElementById('label_' + v).style.visibility='visible'
}
window.onload=handlechange
window.onresize=handlechange
</SCRIPT>
</head>

<body>

<FORM>
<SELECT NAME="sel" ONCHANGE="handlechange()">
<OPTION VALUE="1">1</OPTION>
<OPTION VALUE="2">2</OPTION>
<OPTION VALUE="3">3</OPTION>
</SELECT>

</FORM>
<DIV ID="label_1" style="visibility:hidden">one</DIV>
<DIV ID="label_2" style="visibility:hidden">two</DIV>
<DIV ID="label_3" style="visibility:hidden">three</DIV>

</body>
</html>



Bob
0
 

Author Comment

by:ocean9
ID: 6290996
Thanks for the clear/simple example. It helped.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now