SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict dr_dumb99's Avatar
    Join Date
    Sep 2004
    Location
    Pakistan
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question FireFox Doesn't Check Empty Drop Down Menu

    Hi!
    I have drop down menu on my web page. I have put a javascript check on my web page that when some one clicks a button , this drop down box shouldn't be empty and in case it is empty, it should give alert. This is working fine in IE7. But in FF the Empty Drop Down check doesn't work at all.

    Following is check in javascript:
    <!--
    function mco(){

    theForm = document.frm;
    if(theForm.sp_charges){
    if(!theForm.sp_charges.options[theForm.sp_charges.selectedIndex].value){
    alert("Please Select Shipping Type");
    theForm.sp_charges.focus();
    return false;
    }
    else{
    window.location = '..........';
    }
    }
    else{
    window.location = '..........';
    }
    }
    -->



    Drop Down Selection Box code:

    <select id="sp_charges" name="sp_charges" size="1">
    <option>Select Shipping Type</option>
    <option value="8"> 3-5 Business Days DHL/USPS - $8.00</option>
    <option value="15">2-3 Business Days Express - $15.00</option>
    <option value="25">1-2 Business Days Express - $25.00</option>
    <option value="32">Next Day/24 hour delivery - $32.00</option>
    <option value="INTL">USPS Priority Mail $35.00</option>
    </select>



    Thanks in advance

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dr_dumb99 View Post
    I have drop down menu on my web page. I have put a javascript check on my web page that when some one clicks a button , this drop down box shouldn't be empty and in case it is empty, it should give alert.
    When you say 'empty', presumably you mean on the default option. Your code assumes that the unspecified value of the default option will evaluate to false, which is not certain. You could specify a default value of "", but it would be better just to test the selectedIndex property:
    Code:
    if( theForm.sp_charges.selectedIndex < 1 )
     ...
    Gratitude assumed.
    Tab-indentation is a crime against humanity.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you can do like this:
    Code:
    function mco(){
    	theForm = document.frm;
    	if(theForm.sp_charges.value == "0"){
    		alert("Please Select Shipping Type");
    		theForm.sp_charges.focus();
    		return false;
    	}
    	else{
    		window.location = '..........';
    		return true;
    	}
    }
    HTML Code:
    Drop Down Selection Box code:
    <select id="sp_charges" name="sp_charges" size="1">
    	<option value="0">Select Shipping Type</option>
    	<option value="8"> 3-5 Business Days DHL/USPS - $8.00</option>
    	<option value="15">2-3 Business Days Express - $15.00</option>
    	<option value="25">1-2 Business Days Express - $25.00</option>
    	<option value="32">Next Day/24 hour delivery - $32.00</option>
    	<option value="INTL">USPS Priority Mail $35.00</option>
    </select>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •