Solved

keep value on form refresh

Posted on 2001-07-16
2
357 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Basic JavaScript Question 3 38
angular2 2 way binding on load 7 39
How can i get the length? 7 14
More SharePoint App with Angular and Bootstrap 17 15
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now