Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
In MVC Framework.
 
I have a JavaScript that set the cookie value when I press a link button click. here is the code of my JavaScript:
 <script type="text/javascript" >
    (function() {
        document.getElementById("mylink").onclick = function() { 
            var the_cookie = "video=video;" ; 
            document.cookie = the_cookie;
            //location = 'http://localhost/nproject/index.php?c=files&a=index&active_project=2&1369320566'; 
            //var video = document.getElementById("mylink").value;
            alert(document.cookie.value);
            
        };
    })();
</script>

 
And my link in local pc is :
http://localhost/nproject/index.php?c=files&a=index&active_project=1&1369323644[^]
 
And I don't understand anything about this link as I am a new comer in MVC framework. I have just write this JavaScript in list_files.php. And my link button is on index.php. In index.php I have just add the link as like this:
echo '<div><a id = "mylink" value ="video"'; 
echo 'href="';
get_url('files');
echo '" >Video</a> </div>';
Because, the end of the index.php is :
<?php $this->includeTemplate(get_template_path('list_files', 'files')) ?>
As it is loading my list_files.php.
And when I am clicking on the link its alerting me "undefned". And I have also write my PHP code in list_files.php for getting cookies value in php variable for my another checking.
PHP variable set by Cookie:
<?php if(isset($_COOKIE["video"]))
         { $value = $_COOKIE["video"];
           echo $value;
         }
         ?>
As I am getting the result undefined so, I become confuse to do later jobs. Please help me.
Posted 23-May-13 6:56am
Comments
Mohibur Rashid at 23-May-13 20:50pm
   
you are alerting alert(document.cookie.value);
 
but you were suppose to alert alert(document.cookie);
 
you won't get undefined
 
run this example, it might make sense
<? print_r($_COOKIE);
?>
<script>
</script>
<form >
<input type=submit value='crack' önclick='document.cookie="thedata=value"'>
</form >

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100