justsomeguy Posted November 19, 2010 Share Posted November 19, 2010 Use whichever, each block does the same. Any of these functions will do the same thing, use the one that makes the most sense to you: function error(n) { var errors = { "hi" : { "msg" : "hello", "url" : "http://www.google.com" }, "bye" : { "msg" : "goodbye", "url" : "http://www.bing.com" } }; (errors[n] ? (confirm(n + ": " + errors[n]["msg"]) ? window.location = errors[n]["url"] : return) : alert("Please enter an existing error code."));} function error(n) { var errors = { "hi" : { "msg" : "hello", "url" : "http://www.google.com" }, "bye" : { "msg" : "goodbye", "url" : "http://www.bing.com" } }; ( errors[n] ? ( confirm(n + ": " + errors[n]["msg"]) ? window.location = errors[n]["url"] : return ) : alert("Please enter an existing error code.") ); } function error(n) { var errors = { "hi" : { "msg" : "hello", "url" : "http://www.google.com" }, "bye" : { "msg" : "goodbye", "url" : "http://www.bing.com" } }; if(errors[n]) { if(confirm(n + ": " + errors[n]["msg"])) { window.location = errors[n]["url"]; } else { return; } } else { alert("Please enter an existing error code."); }} Link to comment Share on other sites More sharing options...
koffer08 Posted November 20, 2010 Author Share Posted November 20, 2010 Hey, Well I have no idea what im doing wrong but it’s realy not working, when I change the if statement it makes the same thing as my previous problem or it will just give me internet explorer script error. <script type="text/javascript">function error(n) { var errors = { "hi" : { "msg" : "hello", "url" : "http://www.google.com" }, "bye" : { "msg" : "goodbye", "url" : "http://www.bing.com" } }; if(errors[n]) { if(confirm(n + ": " + errors[n]["msg"])) { window.location = errors[n]["url"]; } else { return; } } else { alert("Please enter an existing error code."); } } window.onload = function() { window.resizeTo(100, 300); window.moveTo(1, 1); document.getElementById("getmessage").onclick = function() { error(document.getElementById("code").value); return false; } }</script><input type="text" id="code" size="3" name="code" maxlength="10" /><input type="submit" id="getmessage" value="S" /> this is the code im using,is there anything wrong with it ? Link to comment Share on other sites More sharing options...
thescientist Posted November 20, 2010 Share Posted November 20, 2010 other than its not working, more specific details could certainly be more helpful. For whatever browser you are using, there will be an option to check for errors, like the error console. a open it up and refresh your browser and see what comes up. This should be the first step when developing and testing javascript code. It's more effective then just guessing. I would recommend trying it with one of the previous suggestions, and report back with any errors if you can't figure them out. Link to comment Share on other sites More sharing options...
koffer08 Posted November 26, 2010 Author Share Posted November 26, 2010 Hey, So I was able to figure it out, adding the code to the one I already have I was forgetting to remove an old bracket. So that’s done. Thank a lot for the help guys. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.