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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.