Solved

keep value on form refresh

Posted on 2001-07-16
2
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

690 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