View Full Version : Not to refresh the selected values...
Coral_Lover
09-24-2002, 03:37 AM
Hi everyone :D, does anyone know how to stop the selected values from being refreshed?? Below are my codes, please let me know, how can i keep the values that are selected in the dropdown menu or entered in the textfield from being reset after the Submit button is clicked?? :confused: My coding is in the attachment... Please help me out. Thank U in advance!!
:D
glenngv
09-24-2002, 03:51 AM
where is the code? :eek:
Coral_Lover
09-24-2002, 04:01 AM
Hmm.. i attached my codes to the message... Nvm, i attach again..
glenngv
09-24-2002, 04:09 AM
a more detailed explanation would help...
Coral_Lover
09-24-2002, 04:28 AM
basically for the web page has two fields which allow me to search for any data in database. for the two fields, when i enter value and press submit button, the fields will become empty. How can i change it to retain the values while displaying the results in the table below??
Coral_Lover
09-24-2002, 04:46 AM
Ok, The 1st field is a dropdown menu, called cboSearch, and the 2nd field is a dynamic field, that means what is selected on the 1st dropdown menu, affects the 2nd field. For example, if i select IP_Address, a textfield will appear and i can enter whatever values for searching. If i select Group_Name, a dropdown menu will appear for u to select the group. Now, here comes the problem---> After i have done the relevant search adn press Submit, the 2 fields will be reset to its default values. But i'm required to retain the values of those 2 fields... Hmm... could u roughly visualise how it works??
glenngv
09-24-2002, 04:55 AM
is this what you wanted?
<%
String txtField = request.getParameter("txtField");
if (txtField==null) txtField="";
%>
<INPUT NAME = "txtField" CLASS = "Search" value="<%=txtField%>">
glenngv
09-24-2002, 04:58 AM
Ooopps that's not what you wanted. I posted it before I read your last post
wait, ill try to fix your prob
glenngv
09-24-2002, 05:05 AM
try this:
<script language=javascript>
<%
String cboSearch = request.getParameter("cboSearch");
%>
function selectSearch(){
var itemToSelect="<%=cboSearch%>";
objSelect = document.Rep.cboSearch;
for (var i=0;i<objSelect.options.length;i++){
if (objSelect.options[i].value==itemToSelect){
objSelect.selectedIndex = i;
changeType();
break;
}
}
}
</script>
Coral_Lover
09-24-2002, 05:21 AM
Thanks Glenn! I've tried ur codes out. But my stupid JSP page still resets the 2 fields. BTW, i can use JSP tags in Javascript??? Anyway, i think the problem may lies in with the function chkOpt(thisForm)... Do u think it's possible with that?? Coz after the fom will process all the JSP coding after the Submit button is being clicked... this is how i called the function>>>
<INPUT TYPE = "BUTTON" CLASS = "btn" NAME = "cmdGenerate" VALUE = "Submit" ONCLICK = "chkOpt(this.Form);
glenngv
09-24-2002, 06:50 AM
i forgot to tell you that you should call the function onload.
<body onload="selectSearch()">
yes you can insert server-side script inside javascript :)
Coral_Lover
09-24-2002, 06:58 AM
Hi Glenn, Thank u so much!!:thumbsup: It works for the 1st field... but how do i retain the values for the 2nd field, which is dynamic (It can be a dropdown menu or textfield)??? :confused:
glenngv
09-24-2002, 07:42 AM
which dynamic field? cboGrp? Isn't the selected item retained? I already called the changeType() function when the first combo is set. This function is the one you call on onchange event of the first combo.
if (objSelect.options[i].value==itemToSelect){
objSelect.selectedIndex = i;
changeType();
break;
}
or am i just on the wrong track?
just a note on your changeType() function.
don't use
Rep.cboSearch.value
to get the value of the combo box.
yes this works in IE but this is not the proper way.
for cross-browser code, use:
//put them in variable since you are referencing Rep and cboSearch many times
var frm = document.Rep;
var objSearch = frm.cboSearch;
var sval = objSearch.options[objSearch.selectedIndex].value;
if((sval== "All") || (sval == "IP_Address"))
//codes here
Coral_Lover
09-24-2002, 08:35 AM
Yes, the 2nd field is dependent on what was selected on the 1st field, consists of 5 dropdown menu, which are invisible and 1 textfield which is visible (When default or when IP_Address is selected in the 1st field) Yah, ur function selectSearch() retains the value in the 1st field but not the 2nd field...
Oic... now then i know there will be difference if i kept using document.xxx.xxx
Thanks! Learn quite a lot from u today.
Coral_Lover
09-24-2002, 08:36 AM
Ok, i attach the latest copy of my JSP page.
glenngv
09-24-2002, 10:08 AM
pls wait, im re-building your whole javascript codes :)
Coral_Lover
09-24-2002, 10:24 AM
Yah, sure, take your time. I'm really happy + grateful that u r willing to help me.. coz i really have little idea of how to retain the values... Once again... REALLY THANK U!!! ^_*
glenngv
09-24-2002, 10:24 AM
ok, here it is... hope i didn't miss something :)
glenngv
09-24-2002, 10:41 AM
if you have any questions regarding the code, i will answer them tomorrow.
Coral_Lover
09-24-2002, 10:46 AM
Ok, thanks for your precious time, while i go n figure out why there's error in the copy that u had attached... Hopefully by tomorrow, i can solved it by tml.
glenngv
09-25-2002, 02:29 AM
im back! what error did you encounter?
Coral_Lover
09-25-2002, 02:42 AM
Hi Glennz! I not v sure abt that error, but it's alrite now... coz i made some changes to the codes and it working fine now. Thank you so much for ur help!! :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.