Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with alert()

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Hi I have the following code that I'm experimenting with...

Code:
<html>
<head>


<script type="text/javascript">

	function disp_mnemonic(mtxt)

	var tl= len(mtxt)
	var x = 1
	var mnem = ""

	for (x=1;x<=tl;x++)
	{

		switch (mid(mtxt,x,1)
		{
		case 'A';
			mnem = mnem+ 'A - Alfa' + '\n'
			break;
		case 'B';
			mnem = mnem+ 'B - Bravo' + '\n'
			break;
		case 'C';
			mnem = mnem+ 'C - Charley' + '\n'
			break;
		case 'D';
			mnem = mnem+ 'D - Delta' + '\n'
			break;
		case 'E';
			mnem = mnem+ 'E - Echo' + '\n'
			break;
		....
		case 'Z';
			mnem = mnem+ 'Z - Zulu' + '\n'
			break;
		}
	}
	{
	alert(mnem);
	}

</script>

</head>
<body>

<% RPwd="RS56QT" %>

<input type="button" onclick="disp_mnemonic('<%=RPwd%>')" value="Display mnemonic box" />

</body>
</html>

The error I'm getting is Object Expected and points to the line.... alert(mnem);

I can't figure out what I'm missing?

Basically I'm trying to port a function I had in vb6 to a web app.

Thanks

I've not failed! Just found 100 ways that don't work...yet!
 
Hi

Try harder. Seems that you not even read the JavaScript specification.
Code:
function disp_mnemonic(mtxt)
[red]{[/red]
    var tl= mtxt[red].length[/red]
    var x = 1
    var mnem = ""

    for (x=1;x<=tl;x++)
    {

        switch (mtxt[red].substr[/red](x,1)[red])[/red]
        {
        case 'A'[red]:[/red]
            mnem = mnem+ 'A - Alfa' + '\n'
            break;
        case 'B'[red]:[/red]
            mnem = mnem+ 'B - Bravo' + '\n'
            break;
        case 'C'[red]:[/red]
            mnem = mnem+ 'C - Charley' + '\n'
            break;
        case 'D'[red]:[/red]
            mnem = mnem+ 'D - Delta' + '\n'
            break;
        case 'E'[red]:[/red]
            mnem = mnem+ 'E - Echo' + '\n'
            break;
        [gray]// ....[/gray]
        case 'Z'[red]:[/red]
            mnem = mnem+ 'Z - Zulu' + '\n'
            break;
        }
    }

    alert(mnem);
[red]}[/red]
And better use another browser. Explorer's error messages are not really helpful. Personally I recommend FireFox with FireBug extension.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top