Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Help with is java script function

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default Help with is java script function

    I have this javascript function that for some unknow reason does not work , can any one please help.

    Code:
    function STUDENTID(){
    	var x=document.getElementById('level_adm').value
    	 if(x != "parent" || x != "student"){
    	document.getElementById('studentid_adm').disabled = true
    	}else if(x == "parent" || x == "student"){
    	document.getElementById('studentid_adm').disabled = false
    	}
    	
    	
    	
    }
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Well, looking at the function alone, we won't be able to fully understand where the problem, might be. Function looks ok as to it's proper syntax. But don't know what studentid_adm or level_adm that it is trying to access. A button? A text box?

    Do you not have a javascript debugger ot javascript console to look at when you run this code? Firefox has both you can use, to see if a error is generated.

    Maybe you could add the accompanying html code so we can see the whole thing in it's context.

  3. #3
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Quote Originally Posted by Arch_Angel View Post
    Well, looking at the function alone, we won't be able to fully understand where the problem, might be. Function looks ok as to it's proper syntax. But don't know what studentid_adm or level_adm that it is trying to access. A button? A text box?

    Do you not have a javascript debugger ot javascript console to look at when you run this code? Firefox has both you can use, to see if a error is generated.

    Maybe you could add the accompanying html code so we can see the whole thing in it's context.
    The thing is the script work perfectly like this :
    Code:
    function STUDENTID(){
    	var x=document.getElementById('level_adm').value
    	if(x != "student"){
    		document.getElementById('studentid_adm').disabled = true
    	}else{
    		document.getElementById('studentid_adm').disabled = false
    	}
    	
    	
    }
    but when i try to evaluate the variable value as shown in the first function it does not work. All i m doing is checking what is the value of x.
    "...men are that they might have joy."
    Nephi

  4. #4
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Hmm ok.

    Why not leave out the 2nd if statement. In fact, code it in a more positive way.
    Code:
    function STUDENTID(){
    	var x=document.getElementById('level_adm').value
    	 if(x == "parent" || x == "student"){
    	document.getElementById('studentid_adm').disabled = false
    	}else{
    	document.getElementById('studentid_adm').disabled = true
    	}	
    }
    BTW, what's the outcome after you run your function? Is studentid_adm disabled or not?
    Last edited by Arch_Angel; Apr 15, 2009 at 04:27 PM. Reason: added extra = signs

  5. #5
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Quote Originally Posted by Arch_Angel View Post
    Hmm ok.

    Why not leave out the 2nd if statement. In fact, code it in a more positive way.
    Code:
    function STUDENTID(){
    	var x=document.getElementById('level_adm').value
    	 if(x == "parent" || x == "student"){
    	document.getElementById('studentid_adm').disabled = false
    	}else{
    	document.getElementById('studentid_adm').disabled = true
    	}	
    }
    BTW, what's the outcome after you run your function? Is studentid_adm disabled or not?
    Thank you so much that worked perfectly
    "...men are that they might have joy."
    Nephi

  6. #6
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default show / hide

    What is i wanted to do a show hide based on the value of the x variable how would that work. I have tried this but no success.
    Code:
    <script type="text/javascript" language="javascript">
    function STUDENTID(){
    	var x=document.getElementById('Level').value
    	if(x == "parent" || x == "student"){
    		document.getElementById('studentid_adm').style.display = 'none';
    	}else{
    		document.getElementById('studentid_adm').style.display = 'block';
    	}
    }
    
    </script>
    "...men are that they might have joy."
    Nephi

  7. #7
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Since I can't see your CSS or HTML, I'll just outline what you need.

    - You need your javascript function that changes the style attribute of the DIV you are trying to hide or show. You javascript looks ok.

    - You need your html with a division (or a similar tag) with an id of 'studentid_adm'. It's a division you are hiding? If not...what?

    - You need your CSS that sets the style display of the division. This is optional I suppose.

    - You need a link to call the javascript function.

    Have all that in place? Any javascript errors? What happens when you try to hide or show the division?

  8. #8
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    the only thing i have changed is to give the studentid_adm to a div instead of a text field, so i dont see why it should not work. No JavaScript errors. Nothing happens when i try to cal the division.
    Last edited by leocrawf; Apr 16, 2009 at 02:24 PM.
    "...men are that they might have joy."
    Nephi

  9. #9
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    The value of X would have to be changed when clicking the link to hide or show the division. Or you setting the X value each time the function is called?

  10. #10
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Quote Originally Posted by leocrawf View Post
    the only thing i have changed is to give the studentid_adm to a div instead of a text field, so i dont see why it should not work. No JavaScript errors. Nothing happens when i try to cal the division.
    Found the error, there was a " missing from the drop down onchange call :

    was
    Code:
    <select name="Level" id="Level" onchange="STUDENTID()>
    should be :
    Code:
    <select name="Level" id="Level" onchange="STUDENTID()">
    of course you could not see that.
    Last edited by leocrawf; Apr 16, 2009 at 02:55 PM.
    "...men are that they might have joy."
    Nephi

Posting Permissions

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