riahc3 50 Â Team Colleague

I copied and pasted that code that you put (which I thank you very much for) and it says "outside undefined"

riahc3 50 Â Team Colleague

The rest of my code is exactly the same.

I have no idea what that .call is (as it is not declared anywhere) but neither is "callback" so......Im just putting what you guys comment. Thank you very much for trying to help me out :) I really appreciate it but I hope you understand that this is really frustrating....

riahc3 50 Â Team Colleague

I wasn't suggesting you copy and paste my code... it was just an example to show you what you are trying to do in it's simplest form. The only piece of code from my post that you should have copied is the _handleMessage() method. You also need to add this.val = value; to the callback function.

I added this:

_handleMessage: function(event){
        if (event.origin == this.origin){
            var data = JSON.parse(event.data);
            //this._requests[data.id].callback(data.key, data.value);
            this._requests[data.id].callback.call(this,data.key, data.value);
            delete this._requests[data.id];
      }

to _handleMessage as you see.....

then......

var remoteStorage = new CrossDomainStorage("http://something.com", "/server.html");
                    remoteStorage.requestValue(stringdepuntos, function(key, value){


                    this.val = value;
                    remoteStorage.val=value;
    alert ("inside val val " + this.val);
    alert ("inside remotestorate val " + remoteStorage.val);

                    })

alert ("outside val " + remoteStorage.val);

and still absolutely nothing at all......

riahc3 50 Â Team Colleague

Well thanks but helpful isnt exactly what I call you answer

riahc3 50 Â Team Colleague

The thing I am MOST annoyed about is no choice. Being forced into this. Thats what pisses me off.

riahc3 50 Â Team Colleague

Order matters?

riahc3 50 Â Team Colleague

The formatting error is probably due to a code check when there's not really any code. Occasionally there seems to be a false positive when checking for indentation, but unfortunately I don't have any solid cases where it always happens. If you could send me some reproduction steps through PM I'll see if I can fix that particular bug. Regardless, removing formatting wouldn't accomplish diddly for avoiding that error since it's a completely separate check. Now, by removing the formatting do you mean highlighting in the editor or all formatting in the final post? I too would like an option to disable formatting in the editor, but I'm having trouble convincing Dani of its usefulness. ;) As far as no formatting in the final post, that would be exceptionally difficult given that we store the contents of a post as raw text with the Markdown characters. To view posts as unformatted would mean either removing the Markdown characters entirely, or simply viewing the raw text. The former might be problematic; I'd need to look through the Markdown parser to see what kind of effort would be involved in removing the formatting characters while preserving the desired text. The latter wouldn't be any better than now as posts would be somewhat hard to read since Markdown wasn't designed as a human consumable raw format. It's better than BBCode, but still designed to be parsed away.

Here is a great example: I click in the quick reply box and it …

riahc3 50 Â Team Colleague

(Sorry for quick posting like that; Just feel like Im close and this has been such a long process)

So close......

riahc3 50 Â Team Colleague

It does what I want; Now I just need it to requestValue (run that and get the value) instead of "bar"

riahc3 50 Â Team Colleague

OK, it prints out "bar" on the outside because I pass bar in the foo function but obviously thats not what I want

riahc3 50 Â Team Colleague

Do I just copy your code or are you putting a example? I ask because I have copied and pasted so many examples (and commented them out again)

riahc3 50 Â Team Colleague

Noone has any idea about this?

riahc3 50 Â Team Colleague

I have this line:

document.cookie =textbox+this.getParameterByName("idProd")+'='+document.getElementById('name').value+'; domain=mydomain.com; expires='+dia.toGMTString()+'; path=/';

This cookie should work on the mydomain.com and all of its subdomains to read and write, correct??? Doesnt work online but works on local thats why I ask.

Thanks!

riahc3 50 Â Team Colleague

Understood :)

How do I add those breakpoints/watches? I feel dumb but I cant find a option :S

riahc3 50 Â Team Colleague

Searching for that debug option, I noticed in the console this:

this._requests[data.id] is undefined
this._requests[data.id].callback(data.key, data.value);

Is this normal?

NOW, if I put a alert, that error does not ocurr.......

riahc3 50 Â Team Colleague

I apoligize if this sounds stupid but how do you add a breakpoint/watch in Chrome/Firebug? Im used to IDEs like VS and MyEclipse so I cant see any similar options.

Thanks for the help.

riahc3 50 Â Team Colleague

REMOVE THE (EXPLETIVE DELETED BY ADMIN) FORMATTING.

It is too annoying. Or at least give people a option of "text only": When Im copying and pasting something I complains about unformatted text or something like that.

It is very very annoying. Give people options and dont force them.

riahc3 50 Â Team Colleague

No because I dont know WHAT to debug :S

I currently have this:

I currently have this:

remoteStorage.requestValue("something", function(key, value){



                valor=value;
                remoteStorage.v=value;



                    hero<?php echo $_SESSION['countforfor']; ?> =  value;
                    document.getElementById("fotop<?php echo $_SESSION['countforfor']; ?>").src=hero<?php echo $_SESSION['countforfor']; ?>;
                    document.getElementById("fotog<?php echo $_SESSION['countforfor']; ?>").src=hero<?php echo $_SESSION['countforfor']; ?>;
                    alert("value " + value);


                });

Which works if I put the alert. If I dont put it, its always the same value.

riahc3 50 Â Team Colleague

Nope.....did not work. I hope you can help me out furhter as this is killing me please :)

I tried that but doesnt work.

alert("hi");
alert("I want to access value here! " + this.request[this.request.length - 1].callback);
alert("bye");

Doesnt reach bye.

riahc3 50 Â Team Colleague

Something like:

<script type="text/javascript">

                /*
 * Copyright 2010 Nicholas C. Zakas. All rights reserved.
 * BSD Licensed.
 */
function CrossDomainStorage(origin, path){
    this.origin = origin;
    this.path = path;
    this._iframe = null;
    this._iframeReady = false;
    this._queue = [];
    this._requests = {};
    this._id = 0;
    this.val="";
}

CrossDomainStorage.prototype = {

    //restore constructor
    constructor: CrossDomainStorage,

    //public interface methods

    init: function(){

        var that = this;

        if (!this._iframe){
            if (window.postMessage && window.JSON && window.localStorage){
                this._iframe = document.createElement("iframe");
                this._iframe.style.cssText = "position:absolute;width:1px;height:1px;left:-9999px;";
                document.body.appendChild(this._iframe);

                if (window.addEventListener){
                    this._iframe.addEventListener("load", function(){ that._iframeLoaded(); }, false);
                    window.addEventListener("message", function(event){ that._handleMessage(event); }, false);
                } else if (this._iframe.attachEvent){
                    this._iframe.attachEvent("onload", function(){ that._iframeLoaded(); }, false);
                    window.attachEvent("onmessage", function(event){ that._handleMessage(event); });
                }
            } else {
                throw new Error("Unsupported browser.");
            }
        }

        this._iframe.src = this.origin + this.path;

    },

    requestValue: function(key, callback){
        var request = {
                key: key,
                id: ++this._id
            },
            data = {
                request: request,
                callback: callback
            };

        if (this._iframeReady){
            this._sendRequest(data);
        } else {
            this._queue.push(data);
        }   

        if (!this._iframe){
            this.init();
        }
    },

    //private methods

    _sendRequest: function(data){
        this._requests[data.request.id] = data;
        this._iframe.contentWindow.postMessage(JSON.stringify(data.request), this.origin);
    },

    _iframeLoaded: function(){
        this._iframeReady = true;

        if (this._queue.length){
            for (var i=0, len=this._queue.length; i < len; i++){
                this._sendRequest(this._queue[i]);
            }
            this._queue = [];
        }
    },

    _handleMessage: function(event){
        if (event.origin == this.origin){
            var data = JSON.parse(event.data);
            this._requests[data.id].callback(data.key, data.value);
            delete this._requests[data.id];
        }
    }

};


var remoteStorage = new CrossDomainStorage("http://somewhere.com", "/server.html");
                    remoteStorage.requestValue(stringdepuntos, function(key, value){
                    alert("The value for '" + key + "' is '" + value + "'");
                    this.val=value;
                    });

              //option 1
            alert ("I want to access value here! " + this.val);

            //option 2
            alert ("I want to access value here! " + val); …
riahc3 50 Â Team Colleague

The entire code is:

<script type="text/javascript">

                /*
 * Copyright 2010 Nicholas C. Zakas. All rights reserved.
 * BSD Licensed.
 */
function CrossDomainStorage(origin, path){
    this.origin = origin;
    this.path = path;
    this._iframe = null;
    this._iframeReady = false;
    this._queue = [];
    this._requests = {};
    this._id = 0;
}

CrossDomainStorage.prototype = {

    //restore constructor
    constructor: CrossDomainStorage,

    //public interface methods

    init: function(){

        var that = this;

        if (!this._iframe){
            if (window.postMessage && window.JSON && window.localStorage){
                this._iframe = document.createElement("iframe");
                this._iframe.style.cssText = "position:absolute;width:1px;height:1px;left:-9999px;";
                document.body.appendChild(this._iframe);

                if (window.addEventListener){
                    this._iframe.addEventListener("load", function(){ that._iframeLoaded(); }, false);
                    window.addEventListener("message", function(event){ that._handleMessage(event); }, false);
                } else if (this._iframe.attachEvent){
                    this._iframe.attachEvent("onload", function(){ that._iframeLoaded(); }, false);
                    window.attachEvent("onmessage", function(event){ that._handleMessage(event); });
                }
            } else {
                throw new Error("Unsupported browser.");
            }
        }

        this._iframe.src = this.origin + this.path;

    },

    requestValue: function(key, callback){
        var request = {
                key: key,
                id: ++this._id
            },
            data = {
                request: request,
                callback: callback
            };

        if (this._iframeReady){
            this._sendRequest(data);
        } else {
            this._queue.push(data);
        }   

        if (!this._iframe){
            this.init();
        }
    },

    //private methods

    _sendRequest: function(data){
        this._requests[data.request.id] = data;
        this._iframe.contentWindow.postMessage(JSON.stringify(data.request), this.origin);
    },

    _iframeLoaded: function(){
        this._iframeReady = true;

        if (this._queue.length){
            for (var i=0, len=this._queue.length; i < len; i++){
                this._sendRequest(this._queue[i]);
            }
            this._queue = [];
        }
    },

    _handleMessage: function(event){
        if (event.origin == this.origin){
            var data = JSON.parse(event.data);
            this._requests[data.id].callback(data.key, data.value);
            delete this._requests[data.id];
        }
    }

};


var remoteStorage = new CrossDomainStorage("http://somewhere.com", "/server.html");
                    remoteStorage.requestValue(stringdepuntos, function(key, value){
                    alert("The value for '" + key + "' is '" + value + "'");

                    });

                    alert ("I want to access value here! " + value);
    </script>

Thanks!

riahc3 50 Â Team Colleague

Nope didnt work....

riahc3 50 Â Team Colleague

I thought that could not be done; didn't even go thru my head..

Javascript is so strange when it comes to its syntaxis.....

Will try tommorow....thank you!

riahc3 50 Â Team Colleague

Hey

This is a stupid and very noob question but lets say I have something like:

<script type="text/javascript">

/*javascript up here*/
var variable = new object("bla", "morebla");    
variable.dosomething("evenmorebla", function(key, value)
{         
alert("key is '" + key + "' and value is '" + value + "'"); 
});

alert ("alert 2 : print and use value on the outside such as here" + value);

/*javascript down here*/

</script>

How can I use/access value in that place where it says alert 2? Thank you very much.

riahc3 50 Â Team Colleague

Im doing this on Firefox and on Firefox and on other browsers it works perfectly local but not online, so its not a browser issue.

It is indeed a client side thing but for some odd reason, acts like this....

riahc3 50 Â Team Colleague

Yes, Javascript is working both remotely and locally as simple alerts show up.

Whats isnt working correctly is this web storage which the thing is that it works on local....Thats the "amazing" part of it...

riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague

i can confirm that the same code (the one on my sites' page) acts differently online that offline.......im puzzled...

The only thing I can think of is that for some reason when I go from one page to another, the value is lost.....but it doesnt happen offline, like i commented.

riahc3 50 Â Team Colleague

Hey

Im using Web Storage for my website and it seems to work locally but not online. Ive tried different thigns (which I shouldnt because it should just work) but it seems not to work. The only conclusion I can come to is that it has been disabled server side.

Is this possible?

riahc3 50 Â Team Colleague

Well it saves/shows a simply session showing "hi"

sessionStorage.setItem("test", "hi");
alert(sessionStorage.getItem("test"));

This shows me hi on the same page.....on another page I go to it doesnt work.

There may be some server side limitation I do not know about so if anything has something to pitch in.....

riahc3 50 Â Team Colleague

It seems to ignore the line completely.....I put a simple Hi and it ignores it.

Could it be something disabled server side? Does session/localstorage need something on the server side?

riahc3 50 Â Team Colleague

So strange........it doesnt even do it the first time online.

riahc3 50 Â Team Colleague

Thanks for the help Biiim

Before, I want to state that this works perfectly on localhost. Has no problems whatsoever.

Let me comment on what you put:

could iframe it and store the javascript var in the parent:
http://stackoverflow.com/questions/935127/how-to-access-parent-iframe-from-javascript

Well it would a "hidden" iframe correct? I dont want a blank window floating arround with data (non sensitive) that Ill just use later on to generate a image

I would database it personally so its not lost on page refresh.

I see it kind of "power hungry" to database the string. Besides, the problem occurs: How do I display that image assosicated with that product? Also that image that be assosicated more than once with the same product.

The page refreshing seems a little odd to me, surely it would go into a redirect loop if it refreshes on every load? have you made sure the $i = 0 var has been set outside the loop so its not being set back to 0 every time and this is done in php not javascript.

It seems somehow Magento controls it (I imagine querying its database) to make sure it doesnt go over its limit on displaying objects. Ive put the counter as the first line :P But with a session variable I was able to control it resetting it because I generate everything on the next page.

What Cereal posted here:
Is getting php to output into javascript:

riahc3 50 Â Team Colleague

Im also using sessionStorage.

riahc3 50 Â Team Colleague

Hmm.......is there a possibility that this only works on local and not on online systems?

For some reason this seems to be the case although I have yet to confirm it 100%. I updated my main site from my local so maybe its some strange cache bug.

riahc3 50 Â Team Colleague

And it works in IE, FF, and Chrome: Good enough for me....

riahc3 50 Â Team Colleague

Finally...........that session variable did it :)

I was scared that the session variable would never restart if I went back and added something else but when I add somethign else, I simply destroy the session variable and recreate it again each time on the page. Works like a charm :)

riahc3 50 Â Team Colleague

OK, theres something I obviously do not now about.......

Each time something is displayed its like the entire code of the PHTML page is ran again. This is why the counter is set back to 0 each time: Because it reloads the ENTIRE page.....

There are 2 things I can do:

1: Find out how this works exactly.
2: Find a unique value that makes it each time load something different.

If you want I can post the entire PHTML page. Not too long.

riahc3 50 Â Team Colleague

Another thing Im contemplating is instead of using PHP counter variable, use Javascript counter variable. Personally I dont care/mind. Maybe having a client side variable would fix this..........?

riahc3 50 Â Team Colleague

Also my PHP hasnt gone crazy
More tests

<?php $countforfor=0; ?>


            <?php foreach ($_options as $_option) : ?>

            <?php $countforfor=$countforfor+1; ?>
            <?php echo($countforfor+1); ?>

This here shows "2" everytime (the echo)

riahc3 50 Â Team Colleague

It perfectly goes thru that line because I put a in alert before it and a out alert after it....

riahc3 50 Â Team Colleague

Still nothing..........that damn countforfor variable doesnt rise

riahc3 50 Â Team Colleague

I feel kind of stupid because maybe Im doing something wrong on this case but to help you see the array structure I did this:

<?php print_r ("I am options " .$_options);  ?>

            <?php foreach ($_options as $_option) : ?>
            <?php print_r ("I am option " .$_option);  ?>

and "I am options" prints out: "I am options Array"
and "I am option" print out the same thing: "I am option Array"

Sorry its the morning :P

Im going to also try adding countforfor to hero as you mentioned. Cant hurt to try...

riahc3 50 Â Team Colleague

I was able to generate one with success :) The only current problem I have is that the entire site is SSLd............I cant SSL just ONE page...

riahc3 50 Â Team Colleague

"internAl"

riahc3 50 Â Team Colleague

Did that too and nothing.....

New code:

<?php $countforfor=0; ?>
            <?php foreach ($_options as $_option) : ?>

            <?php $countforfor=$countforfor+1; ?>
            <input id="xyys" type="hidden" name="xyys" value="<?php echo($_option['value']);echo ($_option['option_id']);?>" /> 

                <?php if($_option['label'] != 'Corte'): ?>

                    <?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
                    <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                    <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>><?php echo $_formatedOptionValue['value'] ?>
                        <?php if (isset($_formatedOptionValue['full_view'])): ?>
                        <div class="truncated_full_value">
                            <dl class="item-options">
                                <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                                <dd><?php echo $_formatedOptionValue['full_view'] ?></dd>
                            </dl>
                        </div>
                        <?php endif; ?>
                    </dd>
                <?php else: ?>
                    <?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
                    <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>


                    <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>>

                    <img id="fotop<?php echo $countforfor; ?>" name="fotop<?php echo $countforfor; ?>" height="100px" width="100px" src=""></img><?php echo Si; ?>


                        <?php if (isset($_formatedOptionValue['full_view'])): ?>
                        <div class="truncated_full_value">
                            <dl class="item-options">
                                <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                                <dd><img id="fotog<?php echo $countforfor; ?>" name="fotog<?php echo $countforfor; ?>" src=""></img><?php echo Si; ?></dd>
                            </dl>
                        </div>




                        <?php endif; ?>
                    </dd>
                <?php endif;?>

                <script type="text/javascript">


                    var hero;


                    hero = '/9jMDAwMDAwMwzYznGXvof1T9u6ziLvD6H9U/bukIfQ/qn7d0hD6H9U/bukI+D6nw/8o8fL7d/q+XSODH36H9U/bukcw+h/VP27pCH0P6p+3dIQ+h/VP27pCH0P6p+3dIQ+h/VP27pCH0P6p+3dIR//9k='; 


                    document.getElementById("fotop<?php echo $countforfor; ?>").src=hero;
                    document.getElementById("fotog<?php echo $countforfor; ?>").src=hero;


                    </script>

                    <?php echo ("hi!");?>
                    <?php echo ("im countforfor ".$countforfor);?>
            <?php endforeach; ?>

(yes, I changed the $count variable's name just in case it was conflicting with another $count somewhere around)

Same thing, the in the countforfor variable the first time around it works. From then on, it does not increment by one.

riahc3 50 Â Team Colleague

You could always set up an internal Certificate server on your network to issue internal certificates for testing. Also, if you are running the website on IIS 7.5, that version supports IIS creating self-signed certificates that is very useful for testing/validation purposes.

Im using Apache. How can I set up a Internet Certificate server on my network?

riahc3 50 Â Team Colleague

Hey

I want to get a (free) SSL certificate so I can test it out (on localhost) before applying it on my real site. This is for a Magento store but should be universal, more or less. Resources? Where should I get it from? How to?

riahc3 50 Â Team Colleague

it also depends on how you want your validation to go.

Im not really sure what you ment by that.

Valid emails:
hi@aol.com
more.names@hello.aol.com

Things like that

Invalid
hiataol.com

hi@aol.com@

riahc3 50 Â Team Colleague

Thank you but the problem is that both http://www.devx.com/tips/Tip/28334 and http://www.devx.com/tips/Tip/42339 still allow invalid email address. Thats the problem with the examples Ive seen on the web: They dont explain anything at all (In a "here is the code, take it and use it" style) and some are outdated.