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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AJAX: Pass vale to Server from Javascript

    Hello

    I am using PlainAjax. http://coolpenguin.net/plainajax/?p=examplespostdata

    Here is my code and it is not working if i called from Javascript function.

    Code:
    <script type="JavaScript" src="plainajax.js"></script>
    <script language="JavaScript" >
    
    function openWin()
    {
    	.......		
    	.......
    	.......
    	var selval = selectedValue.toString();	 	// Dynamic value variable
    	document.formlist.myval.value = selval; 	// stored to hidden variable
    
    	
    	 var cn = document.getElementById( "itsme" ).childNodes;	// Get all the nodes
    	
    	 var myresult = new Array();					// declare result array
        	 plainajax.request('respurl: req_php.php; resultloc: myresult; paramloc: cn;');
      
    	 Window.open("req_php.php");
    	
    }
    
    </script>
    
    <html>
    
     <div id="itsme">
    
    	<input type="hidden" name="myval" id="myval" value=""> 
    </div>
    
    </html>

    req_php.php
    =========
    Code:
    <?php
    
    		echo "value from html = ".$_REQUEST['myval']."<br>";
    	
    ?>


    But i am not able to get any value in my php program. What i did wrong in this?

    or is anyother way to pass the variable from Javascript (except pass thru url query string, this is not secure)

    Thanks

  • #2
    Regular Coder byuhobbes85's Avatar
    Join Date
    Oct 2006
    Location
    Ames, Iowa, USA
    Posts
    116
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Your input is a hidden input, which means the user can't alter it. Since that hidden input is an empty string, your PHP script is probably printing out the correct value--an empty string (which prints nothing on the screen).
    -- </byuhobbes>


  •  

    Posting Permissions

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