Jump to content

Get the value of an Input variable and display it on another form on the same pa


grs5211

Recommended Posts

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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.