www.webdeveloper.com
Results 1 to 2 of 2

Thread: send value to javascript function

  1. #1
    Join Date
    Apr 2010
    Location
    Cairo,Egypt
    Posts
    33

    send value to javascript function

    Hello,
    In the following code i'm trying to check if the value of the text field is exist in the array.
    the problem that the function dose not accept the the value(node.value) from the text field.


    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>Text Validation</title>
    <script type="text/javascript" language="javascript">
    
    
    Array.prototype.inArray = function (value)
    {
    // Returns true if the passed value is found in the
    // array. Returns false if it is not.
    alert(value);
    var i;
    for (i=0; i < this.length; i++) 
    {
    	if (this[i] == value) 
    	{
    
    	return true;
    	}
    }
    
    return false;
    };
    function cal(xx)
    {
    
    
    	var node_list = document.getElementsByTagName('input');
    	arr = new Array(""); 
    	for (var i = 0; i < node_list.length; i++)
    	 {
    		var node = node_list[i];
    	///alert(node_list.length);
    	//	alert(node.value);
    
    
    arr.push(node.value)
    }
    alert(xx.length);
    	//var arr= new Array(1,2,3,4,5,6,7,8,9,10);
    	if(xx.length!=0)
    	{
    		if(arr.inArray(xx))
    		{
    			alert("Your value is found in the Array");
    		}
    		
    		else
    		{
    			alert("Your value is not found in the Array");
    		}
    	}
    }
      
    
    </script>
    </head>
    
    <body>
    <form id="text_validation" name="text_validation" action="" method="post">
    <table width="600" border="1">
      <tr>
        <td><label for="abc_text_1" id="abc_text_1_lb">Text 1</label> </td>
        <td>:</td>
        <td><input type="text" id="abc_text_1" name="abc_text_1" onblur="return cal(this.value);" /></td>
      </tr>
      <tr>
        <td><label for="cde_text_2" id="cde_text_2_lb">Text 2</label> </td>
        <td>:</td>
        <td><input type="text" id="cde_text_2" name="cde_text_2"  value="abc"  /></td>
      </tr>
      <tr>
        <td><label for="fgh_text_3" id="fgh_text_3_lb">Text 3</label> </td>
        <td>:</td>
        <td><input type="text" id="fgh_text_3" name="fgh_text_3"   value="abcaaaaa" onblur="return testvalidation(fgh_text_3);" /></td>
      </tr>
      <tr>
        <td><label for="ijk_text_4" id="ijk_text_4_lb">Text 4</label> </td>
        <td>:</td>
        <td><input type="text" id="ijk_text_4" name="ijk_text_4"  onblur="return testvalidation(ijk_text_4);" /></td>
      </tr>
      <tr>
        <td><label for="lmn_text_5" id="lmn_text_5_lb">Text 5</label> </td>
        <td>:</td>
        <td><input type="text" id="lmn_text_5" name="lmn_text_5"  onblur="return testvalidation(lmn_text_5);" /></td>
      </tr>
      <tr>
        <td><label for="opq_text_6" id="opq_text_6_lb">Text 6</label> </td>
        <td>:</td>
        <td><input type="text" id="opq_text_6" name="opq_text_6"  onblur="return testvalidation(opq_text_6);" /></td>
      </tr>
      <tr>
        <td><label for="rst_text_7" id="rst_text_7_lb">Text 7</label> </td>
        <td>:</td>
        <td><input type="text" id="rst_text_7" name="rst_text_7" /></td>
      </tr>
      <tr>
        <td><label for="uvw_text_8" id="uvw_text_8_lb">Text 8</label> </td>
        <td>:</td>
        <td><input type="text" id="uvw_text_8" name="uvw_text_8" /></td>
      </tr>
      <tr>
        <td><label for="xyz_text_9" id="xyz_text_9_lb">Text 9</label> </td>
        <td>:</td>
        <td><input type="text" id="xyz_text_9" name="xyz_text_9" /></td>
      </tr>
      <tr>
        <td><label for="klm_text_0" id="klm_text_0_lb">Text 10</label> </td>
        <td>:</td>
        <td><input type="text" id="klm_text_0" name="klm_text_0" value="10" /></td>
      </tr>
    </table>
    
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    To be frank, I don't understand what is the use of your code. You create an array with all the values of the input elements and you compare one of those values with the array's elements. Obviously, that value will be always within the arrays elements, because you create that array on adding that value each time, that means the custom method inArray will always return true.

    Anyway, I don't understand your problem either. Even if it is not logical, the code works, and the textfields values are accepted (nor shouldn't be otherwise).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles