views:

171

answers:

6

I'm looking for a simple javascscript alert box. I need to be able to pass the alert box a string of text.

Is something like this possible? My syntax is probably wrong.

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert(my_string_here);
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" string="alert for system number 2" />

</body>
</html>
A: 

alert("alert for system number 2");

Jack
+3  A: 
<html>
<head>
<script type="text/javascript">
function show_alert(my_string)
{
alert(my_string);
}
</script>
</head>
<body>

<input type="button" onclick="show_alert('This will alert!')" value="Show alert box" string="alert for system number 2" />

</body>
</html>

This makes no sense thou. Better solution:

<html>
<head>
</head>
<body>

<input type="button" onclick="alert('Doh!')" value="Show alert box" string="alert for system number 2" />

</body>
</html>
Björn
although hopefully you're not still using inline event handlers for everything...
CrazyJugglerDrummer
No, but _this_ example didn't make any sense. There's no need to create a separate function that does _the exact same thing_ as a regular alert() does.
Björn
A: 

What are you trying to do? alert('Your string here') should do the trick if you really need an alert.

Ori Pessach
+1  A: 

Try:

<input type="button" onclick="alert('alert for system number 2');" value="Show alert box" />
Ian Devlin
A: 

Yes you can

function testAlert(val){alert(val);}

Bandpay
A: 

Yes this is possible

<script type="text/javascript">
function testAlert(val){alert(val);}
</script>

<input type=text onclick='testAlert(this.string)' string="something" value="clik here">
Bandpay