Jump to content

Validate list box


rashmi_k28

Recommended Posts

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>


 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.