Jump to content

Message box based on value in textbox


koffer08

Recommended Posts

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

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

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

Archived

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

×
×
  • Create New...