Results 1 to 2 of 2

Thread: How to get return value in Javascript

  1. #1
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to get return value in Javascript

    Dear Guys,

    I have a question about Javascript because I am new in javascript my problem is how to get return true value in my code here my code

    Code:
    <script type="text/javascript" charset="UTF-8" language="javascript">
    function numbersonly(myfield, e, dec)
    {
    	var key;
    	var keychar;
    	if (window.event)
    		key = window.event.keyCode;
    	else if (e)
    		key = e.which;
    	else
    
    		return true;
    	keychar = String.fromCharCode(key);
    	if ((key==null) || (key==0) || (key==8) || 
    		 (key==9) || (key==13) || (key==27) )
    function returnnum(){
    }
    
    if (window.event)
    key= window.event.keyCode;
    document.element
    else
    		return true;
    	
    	else if ((("01").indexOf(keychar) > -1))
    		return true;
    	
    	else if (dec && (keychar == "."))
    		{
    		myfield.form.elements[dec].focus();
    		return false;
    		}
    	else
    		return false;
    }
    function checkUncheckAll(theElement) 
    {
    	var theForm = theElement.form, z = 0;
    	for(z=0; z<theForm.length;z++)
    	{
    		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
    		{
    		  theForm[z].checked = theElement.checked;
    		}
    	}
    }
    
    function checkUncheckSome(controller,theElements) 
    {
    	var formElements = theElements.split(',');
    	var theController = document.getElementById(controller);
    	for(var z=0; z<formElements.length;z++)
    	{
    		theItem = document.getElementById(formElements[z]);
    		if(theItem.type)
    		{
    			if (theItem.type=='checkbox') 
    			{
    				theItem.checked=theController.checked;
    			}
    		} else {
    			theInputs = theItem.getElementsByTagName('input');
    			for(var y=0; y<theInputs.length; y++)
    			{
    				if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id)
    				{
    					theInputs[y].checked = theController.checked;
    				}
    			}
    		}
    	}
    }
    </script>
    because my main purpose is to disable other number only 1 and 0 will input if you enter 1 only 1 no other number in one text attach here is my screen shot in the primary is different input box if you enter 1 only and in the second if you enter 0 only will appear do you have idea.

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <input type="text"
           onkeypress="
             return '01'
                 .split()
                 .indexOf(String.fromCharCode(event.which || event.keyCode))
               >= 0;
           ">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •