...

View Full Version : combo box!!!!!!!!!!



tanhaha_how
02-24-2006, 04:18 AM
Why everytime i refresh the page....what i selected in the combo box will also refresh(disappear)....but for text box, i write like this...the text box that user enter...can maintain inside the text box...urgent!!!!help me pls...



<select name="txtDate2" id="dates" <%if haha<>"cancel" then%>value="<%=request("txtDate2")%>"<%else%>value=""<%end if%>>
<option value="0">---</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

ihitman
02-24-2006, 10:56 AM
If you REFRESH the page, the page and all the content in it will be refreshed, meaning everything you have entered without saving will disappear.

tanhaha_how
02-24-2006, 12:15 PM
but the text box below...the content still appear when i refresh the page....can sombody tell me why please????

[code]
<td colspan=5><input type="text" name="amount" onkeypress="return isNumberKey(event)" value="<%if haha<>"cancel" then%><%=server.HTMLEncode(request("amount"))%><%end if%>"><% if subop6="erroramount" then %><span class="red">*</span><% end if %></td>
</tr>
[/cede]

ihitman
02-24-2006, 12:18 PM
Because the value of the text field is dependant on the value of the variable 'haha'. So when you refresh the page, if the variable haha does not equal cancel, then the value of the text field will have something in it.

Apply the same principle to the values in the dropdown, eg.

<option value="0" <%=If yourVariable="0" Then Response.Write "selected"%>>---</option>

tanhaha_how
02-24-2006, 12:34 PM
so is it using ur way....the value inside the combo box that is choose by the user will always appear even thought i refresh it???

:confused:

ihitman
02-24-2006, 12:37 PM
:( If you refresh the page and there is no data that can be used to base other elements on the form on, then they will be refreshed and await the user to enter/select them.

If you have server side data that can be used to select the appropriate value on the combo box, when you refresh it, it will use this data to reselect the value in the dropdown.

degsy
02-24-2006, 02:26 PM
If you are wanting to show the selected option then here is an example



<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="">
<select name="mySelectBox">
<%For x=1 to 20%>
<option value="<%=x%>"<%If Cstr(x)=Cstr(Request.Form("mySelectBox")) Then Response.Write " selected"%>>Option: <%=x%></option>
<%Next%>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
<p>
<%
If Request.Form("mySelectBox") > 0 Then
Response.Write "you chose option: " & Request.Form("mySelectBox")
End If
%>
</p>
</body>
</html>

tanhaha_how
02-25-2006, 02:30 AM
Yes....That's what i want...you are great....Thank you very much....

Another problem again....You did for me is DAY....How about my month follow with year?????????thanks



<script type="text/javascript">
function addMonths() {
var MONTHS=["Jan", "Feb", "Mar ", "Apr ", "May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec "];
var today=new Date();
var thisYear=today.getFullYear();
var thisMonth=today.getMonth();
for (var x=0; x<=thisMonth; x++) { // Use this if you want January to be first
//for (var x=thisMonth; x>=0; x--) { // Use this if you want the current month to be first
var option = document.createElement('option');
option.value=thisMonth+1;
var text = document.createTextNode(MONTHS[x]+'-'+thisYear);
option.appendChild(text);
document.getElementById('months').appendChild(option);
}
}
</script>

<select name="txtDate1" id="months">
<option>---</option>
</select>
<% if subop8="errordate" then%><span class="red">*</span><% end if %>


What should i write?????

degsy
02-27-2006, 04:00 PM
I'm not sure what you mean. What are you trying to achieve?

tanhaha_how
02-28-2006, 12:21 PM
i've tried to use the same method in second combo box(months follow with year)like yours...but the the 2nd combo box still disapper againafter i click submit button(like the first problem on top)...why??

how should i fix it??

thanks

degsy
02-28-2006, 03:13 PM
Another problem again....You did for me is DAY....How about my month follow with year?????????thanks


i've tried to use the same method in second combo box(months follow with year)like yours

Sorry, but I do not know what you mean.

tanhaha_how
03-01-2006, 04:14 AM
sorry....

i mean how can i use this method apply inside my code??



<option value="<%=x%>"<%If Cstr(x)=Cstr(Request.Form("mySelectBox")) Then Response.Write


my code:



<script type="text/javascript">
function addMonths() {
var MONTHS=["Jan", "Feb", "Mar ", "Apr ", "May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec "];
var today=new Date();
var thisYear=today.getFullYear();
var thisMonth=today.getMonth();
for (var x=0; x<=thisMonth; x++) { // Use this if you want January to be first
//for (var x=thisMonth; x>=0; x--) { // Use this if you want the current month to be first
var option = document.createElement('option');
option.value=thisMonth+1;
var text = document.createTextNode(MONTHS[x]+'-'+thisYear);
option.appendChild(text);
document.getElementById('months').appendChild(option);
}
}
</script>

<select name="txtDate1" id="months">
<option>---</option>
</select>


thank you:)

glenngv
03-01-2006, 05:22 AM
function addMonths() {
var MONTHS=["Jan", "Feb", "Mar ", "Apr ", "May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec "];
var today=new Date();
var thisYear=today.getFullYear();
var thisMonth=today.getMonth();
for (var x=0; x<=thisMonth; x++) { // Use this if you want January to be first
//for (var x=thisMonth; x>=0; x--) { // Use this if you want the current month to be first
var option = document.createElement('option');
option.value=thisMonth+1;
if (option.value=="<%=request.form("txtDate1")%>"){
option.setAttribute("selected", "selected");
}
var text = document.createTextNode(MONTHS[x]+'-'+thisYear);
option.appendChild(text);
document.getElementById('months').appendChild(option);
}
}
</script>

<select name="txtDate1" id="months">
<option>---</option>
</select>

tanhaha_how
03-01-2006, 07:33 AM
i've test it already....the combo box will automatically shows the current year no matter what user have been selected and click submit button.....

can you please help me again????

thank u very much.

tanhaha_how
03-02-2006, 09:28 AM
I've changed to this code below.....but the the combo box will automatically jump to ---.....can anyone help me please??



<select name="txtDate1" id="months" value="<%=request("txtDate1")%>">
<option value="0">---</option>
<%
txtDate3 = DatePart("yyyy", Date())
Dim j
For j=1 To Month(Date)
%>
<option value="<%=CStr(MonthName(j,true)) & "," & " " & CStr(txtDate3)%>" <%if CStr(request("txtDate1")) = CStr(MonthName(j,true)) and subop<>"cancel" then%>selected<%end if%>><%=CStr(MonthName(j,true)) & "," & " " & CStr(txtDate3)%></option>
<%
Next
%>
</select>


Thanks in advance.

degsy
03-02-2006, 03:19 PM
<select name="txtDate1" id="months" value="<%=request("txtDate1")%>">
The select element doesn;t have a value attribute. What you have there is pointless.



Give an example of what request("txtDate1") should be

tanhaha_how
03-03-2006, 05:43 PM
it's ok..i've solved it dee......thank u very much....

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum