rashmi_k28 Posted April 15, 2008 Share Posted April 15, 2008 Hi, I tried to validate the List box as shown below. But it is not working. Please tell me what is the problem. What I feel is may be because of the query string with file name. So how can I solve this problem <script> function validate(){ if(document.searchType.src_type.value == 'topn'){ if((document.searchType.os.value == '--') && (document.searchType.type.value == '--')){ alert("Select Criteria"); document.searchType.os.focus(); return false; } } } </script> <form id=searchType name=searchType method="get" onSubmit="return validate();" action="<?=$_SERVER['PHP_SELF']?>"> <div style="width:980px; top:20px;" align="center"><label><font size="4" color="#006699" face="Arial">SEARCH</font></label></div> <div style="width:980px; top:20px;" align="center"> <table border="0" cellpadding="0" cellspacing="8"> <tr> <td><a href=search.php?src_type=res>Resource</a></td> <td><a href=search.php?src_type=soft>Software</a></td> <td><a href=search.php?src_type=topn>Top N</a></td> </tr> </table> </form> <hr> <? if(isset($_GET["src_type"])){ $src_type = $_GET["src_type"]; echo "<form id=searchRule method=get action=searchResult.php>"; echo "<input type=hidden name=src_type value=$src_type>"; echo "<input type=hidden name=st_index value=0>"; echo "<input type=hidden name=rpp value=20>"; eif("topn" == $src_type){ ?> <div style=width:760px align=center> <table border=0 cellpadding=0 cellspacing=8> <tr> <td align="left"><label><font size=4 color="#006699" face="Arial">TopN Search </font></label></td> </tr> </table> </div> <div style=width:980px align=center> <table border=0 cellpadding=0 cellspacing=8> <tr> <td align="left"><label><font color="#006699" face="Arial">Operating System </font></label></td> <td align=left> <select id="os" name='os'> <option value="--" selected>-- <option value="AIX">AIX <option value="Linux">Linux <option value="Solaris">Solaris </select> </td> </tr> <tr> <td align="left"><label><font color="#006699" face="Arial">Category</font></label></td> <td align="left"><select id="type" name="type"> <option value="--" selected>-- <option value="free">Free Memory <option value="tot_mem">Total Memory <option value="cpu_speed">CPU Speed <option value="no_of_processors">No. Of CPUs </select> </td> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted April 15, 2008 Share Posted April 15, 2008 1) Number one your closing you form tag on top </form> please close it after the select box 2) changed onSumbit="return validate();" to onsubmit="return validate(this)" 3) next changed the function as follows <script> function validate(f){ if(f.src_type.value == 'topn'){ if((f.os[f.os.selectedIndex].value == '--') && (f.type[f.type.selectedIndex].value == '--')){ alert("Select Criteria"); f.os.focus(); return false; } } } </script> hope its helpful Quote Link to comment Share on other sites More sharing options...
rashmi_k28 Posted April 16, 2008 Author Share Posted April 16, 2008 Hi, Thanks for the reply.f I close form after the list box the page is not taken to searchResult.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.