Javascript problem when history(-1) applied.

U

U?ur Aslan

I made a form that includes a list box (select-options) that has
numbers from 1 to 10 as option values. When user selects one of the
numbers from the list box, an innerHTML is inserted into a "div" part
in the page as much as the selected number value. This is done by a
javascript that is handled by onchange event in <select> tag. Once the
form is submitted by user, the user can go back to change the values
that he has written in the form. The problem is that when the user
hits the back button, the value selected in list box remains same but
the innerHTML part disappears as if user did not select any number.
This can be natural and normal but I need a solution. If you can help
me, I will be very pleased. Thank you.

The code : (options tags are filled by ASP)

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function degistir(sayi){
if (sayi != 0){
var text2 = "";
for (i=1; i<= sayi; i++)
{
text2= text2 + i + "Hello!<br>"

}
var Divx = document.getElementById("div1");
Divx.innerHTML = text2;
}
}

</SCRIPT>
</HEAD>
<BODY>
<form name=form1>
<Select name=select1
onchange="degistir(this.options[this.selectedIndex].value)">
<option value="0">Seçiniz
<% for i=1 to 10 %>
<option value=<%=i%>><%=i%>
<% next %>
</select>
<input type="submit" value="git">
</form>
<div id="div1"></div>
</BODY>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top