Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Script not working in FF

    The validation script below works in IE but not in FF. Any suggestions?

    Site: spendandgive.biz

    Code:
    <script>
    
    	function validate2(){
    		
    		if(document.form1.shop.value == ''){
    			alert('Please select your shop before continuing!');
    			document.form1.shop.focus();
    			return false;
    		}
    		if(document.form1.charity.value == ''){
    			alert('Please select your charity before continuing');
    			document.form1.charity.focus();
    			return false;
    		}
    	
    	
    						
    }
    </script>

  • #2
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Try adding something like..

    Code:
    var form = document.getElementById('form1');
    Then in place of document.form1....

    form.charity.value ==''

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,556 Times in 2,534 Posts
    What are shop and charity? Are they values obtained from textboxes, radio buttons, checkboxes or select lists?

    Suggest you post your relevant HTML markup.

  • #4
    New Coder
    Join Date
    Oct 2003
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Select lists.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,556 Times in 2,534 Posts
    I did ask you to post your relevant HTML mark-up.

    The following works fine in both IE and Firefox, and I see nothing in what you have posted so-far to explain why you have a problem with FF.

    Code:
    <form name = "form1">
    <select name = "shop">
    <option value = "">Select a shop</option>
    <option value = "Shop1">Shop1</option>
    <option value = "Shop2">Shop2</option>
    </select>
    
    <select name = "charity"> 
    <option value = "">Select a charity</option> 
    <option value = "Charity1">Charity1</option>
    <option value = "Charity2">Charity2</option>
    </select>
    
    <input type = "button" name = "but1" value = "Validate" onclick = "validate2()">
    </form>
    
    <script type = "text/javascript">
    	function validate2(){
    		
    		if(document.form1.shop.value == ''){
    			alert('Please select your shop before continuing!');
    					return false;
    		}
    		if(document.form1.charity.value == ''){
    			alert('Please select your charity before continuing');
    						return false;
    		}
    
    				
    }
    </script>

  • #6
    New Coder
    Join Date
    Oct 2003
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Sorry I didnt have access to the code at the time, but here is the select script. Check out spendandgive.biz and you will see it doesnt work in FF.

    Code:
    1. <select name='shop' class="bodytxt" size="1" id="shop_id" onChange="return select_server();">
                                                          <option>---Select your shop----</option>
    													  <?php 	$sql = mysql_query("select * from ".SHOP." order by shop_name asc ") or die( mysql_error());
    								while($rs = mysql_fetch_array( $sql )){
    							?>
    							<option value="<?=$rs['shop_id']?>"><?=$rs['shop_name']?></option>
    						   	<?php
    								}
    							?>
                                                    </select>
    												
    </td>
    <td><center>
    
    2. <select name="charity" class="bodytxt" size="1">
                                                          <option>---Select your charity----</option>
    													  <?php 	$sql = mysql_query("select * from ".CHARITY." order by charity_name asc ") or die( mysql_error());
    								while($rs = mysql_fetch_array( $sql )){
    							?>
    							<option value="<?=$rs['charity_id']?>"><?=$rs['charity_name']?></option>
    						   	<?php
    								}
    							?>
                                                      </select>

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,556 Times in 2,534 Posts
    Agreed something weird is happening in FF.

    Use some temporary alerts to help identify the problem:-

    function validate2(){

    alert (document.form1.shop.value);
    alert (document.form1.charity.value);


    if(document.form1.shop.value == ''){

  • #8
    Banned
    Join Date
    May 2005
    Location
    Midwest, U.S.
    Posts
    118
    Thanks
    1
    Thanked 26 Times in 23 Posts
    @tomraffe
    Validate your mark-up. You are missing the closing form tag, along with 66 other errors.

    Place ALL script tags within the Head section. JavaScript has no place inside the Body. None.

    http://validator.w3.org/

    http://jigsaw.w3.org/css-validator/

    P.S.

    This: http://www.tizag.com/javascriptT/jav...theadnbody.php

    is garbage. It wasn't valid in 2003 when the site was started and it isn't valid today. Garbage, dressed up in arrogance and pretension. Garbage.
    Last edited by Cranford; 01-27-2009 at 09:57 PM.

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,556 Times in 2,534 Posts
    Quote Originally Posted by Cranford View Post
    Place ALL script tags within the Head section. JavaScript has no place inside the Body. None.
    For a less dogmatic opinion see:-
    http://www.tizag.com/javascriptT/jav...theadnbody.php

    The location choice of head or body is very simple. If you want to have a script run on some event, such as when a user clicks somewhere, then you will place that script in the head. If you want the script to run when the page loads, like our "Hello World!" example in the previous lesson, then you will want to place the script within the body tag.


    JavaScripts in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, other times when a user triggers an event.
    Scripts in the head section: Scripts to be executed when they are called, or when an event is triggered, go in the head section. When you place a script in the head section, you will ensure that the script is loaded before anyone uses it.
    Scripts in the body section: Scripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page.
    Scripts in both the body and the head section: You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.


  •  

    Posting Permissions

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