1

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>
1
  • I know my example makes no sense, I'm not a JS guru. thank you Bjorn for the tip, that worked perfect! Commented Nov 4, 2009 at 21:10

6 Answers 6

4
<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>
Sign up to request clarification or add additional context in comments.

2 Comments

although hopefully you're not still using inline event handlers for everything...
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.
1

Try:

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

Comments

0

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

Comments

0

Yes you can

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

Comments

0

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">

Comments

0

alert("alert for system number 2");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.