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 6 of 6

Thread: Adding To Code

  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Adding To Code

    I have this code:

    Code:
    $('#menuitemform select').change( function() {
                $( '#menuitemform select' ).not( this ).val( 0 );
            });
    to prevent the user from making a selection from more than 1 select dropdown however I want to add something to this but not sure how.

    Along with this I want to make the user not be able to also have input inside of a text box if one of the dropdowns has a selection. If one of them does then it erases the users input but its on a specific text box with an id of itemurl.
    Last edited by CoolAsCarlito; 01-17-2011 at 09:01 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    If I understand correctly:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('#menuitemform select').change( function() {
    	$('#menuitemform select' ).not(this).val(0);
    	if($("#s1").val().length > 0){
      		$("#itemurl").attr("value","");
    
    	}
    });
    
    });
    </script>
    </head>
    
    <body>
    <form id="menuitemform" method="POST" action="">
    	<select name="s1" id="s1">
    		<option value="">Select</option>
    		<option value="apples">Apples</option>
    		<option value="oranges">Oranges</option>
        </select>
    	<select name="s2" id="s2">
    		<option value="">Select</option>
    		<option value="lions">Lions</option>
    		<option value="tigers">Tigers</option>
        </select>
        <input id="itemurl" name="itemurl" ttype="text" />
    </form>
    </body>
    </html>
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • Users who have thanked harbingerOTV for this post:

    CoolAsCarlito (01-17-2011)

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    So I was able to get it to work the way I asked however I wanted to also extend it so that if there was a value in the input field then the 3 dropdowns would reset back to the 0 values but its saying there is a js error which could only involve the code below.

    Code:
    $('#menuitemform select').change( function() {
                $( '#menuitemform select' ).not( this ).val( 0 );
                if ($("#menuitemform select").val().length > 0){
          		    $("#itemurl").attr("value","");
                }
            });
            if $("#itemurl").val().length > 0){
                $( '#menuitemform select' ).not( this ).val( 0 );
            }
    Last edited by CoolAsCarlito; 01-17-2011 at 08:15 PM.

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    So if any select has a chosen value, let it e the only select that has value and clear the input.

    But, If the input has value, reset the selects?

    right?

    try:
    Code:
    $('#menuitemform select').change(function(){
    	$("#itemurl").removeAttr('disabled');
    	$('#menuitemform select').not(this).val(0);
    	$('#menuitemform select').each(function(){
    		if($(this).val().length > 0){
      			$("#itemurl").attr("value","");
    			//$("#itemurl").attr('disabled','disabled');
    		}
    	});
    });
    $("#itemurl").focus(function(){
    	$('#menuitemform select').val(0);
    });
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • Users who have thanked harbingerOTV for this post:

    CoolAsCarlito (01-17-2011)

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    GENIUS. However is it safe for me to delete that commented line. And thank you VERY MUCH.

  • #6
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    More than safe. i was just using it for testing.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • Users who have thanked harbingerOTV for this post:

    CoolAsCarlito (01-17-2011)


  •  

    Posting Permissions

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