grs5211 Posted May 26, 2009 Share Posted May 26, 2009 I have filled an Input box with a value obtained by getting a cookie value at the start of code. This works fine. Now I want to input "aCode" with this value within the same form. Here is the code to get the cookie, which works, but the rest does not. NB. I am new to PHP. <head> function checkCookie() { if(document.getElementById("userid").value == "") { cookieCASUserIDValue = getCookie("CUserID"); if(cookieCASUserIDValue != null) { document.getElementById("userid").value = getCookie("CUserID"); } } </head> <body class="gradient" onLoad="checkCookie();"> <form id="gData" name="gData" method="POST"> <input type="text" id="userid" name="userid" size=8 >' /> <input type="text" name="aCode" id="aCode" style="display: none;" value=document.getElementById("userid").value> </input> </form> } At this stage I wish to get the value of the element "userid" and and display it. Here is my code that does not wotk. <?php error_reporting(1); // Only display error messages, not warnings and notices. echo "UserID = " . $_REQUEST["userid"]; . "<br>"; ?> Can anyone help! Quote Link to comment Share on other sites More sharing options...
Brian W Posted May 26, 2009 Share Posted May 26, 2009 if you use the code tags around your php or even html snippets, you will likely get more help [ code ]Like this but without the spaces in the tags[ /code ] would be Like this but without the spaces in the tags Try: <?php error_reporting(1); // Only display error messages, not warnings and notices. echo "UserID = " . $_REQUEST["CUserID"]; . "<br>"; ?> Else, you could do this in java script also like the below: <!--if you haven't set the cookie somewhere else, this isn't going to work--> <head> <script language="javascript" type="text/javascript"> function checkCookie() { if(document.getElementById("userid").value == ""){ cookieCASUserIDValue = getCookie("CUserID"); if(cookieCASUserIDValue != null){ document.getElementById("userid").value = getCookie("CUserID"); document.getElementById("aCode").value = getCookie("CUserID"); document.getElementById("userid_display").innerHTML = "User Id = " + getCookie("CUserID"); } } } function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; } </script> </head> <body class="gradient" onLoad="checkCookie();"> <form id="gData" name="gData" method="POST"> <input type="text" id="userid" name="userid" size=8 > <input type="hidden" name="aCode" id="aCode" value=""> </form> <div id="userid_display"></div> </body> In that example, I've cleaned up your code, fixed things A LOT . Good luck and I wish you the best in learning. Quote Link to comment Share on other sites More sharing options...
grs5211 Posted May 26, 2009 Author Share Posted May 26, 2009 Thanks, that solved the problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.