Jump to content

Help: Running a function when clicked.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Bannana97

Bannana97

    Newbie

  • Members
  • Pip
  • 5 posts
How would I?

How do I make a function too?

do I use:

<function install()>
COMMAND
</function>

?

And How would I run it?

Like this?:

onclick="javascript:function install()"

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I suggest you read more about javascriptWiki. Usually, those are written within <script> tags in the html page, or linked to a separate file, with the same tag.

It is a little bit large subject to describe here, but take a look at W3Schools Online Web Tutorials, where this is one of the javascript tutorials you want to look at: Tryit Editor v1.4

#3
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Every object has a set of events. Onclick is the one that occurs (of course) when the button (or other input) is clicked.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#4
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
as orjan said you must read about JS first
anyways heres a little pointers:
-to connect a control with an event to start a function, first you need to write the JS function in the <script> tags, then call the function from the html control, heres a page with an alert function

<html>

<head>

<script type="text/javascript">

  function msg()

  {

        alert('you clicked a button');

        //do commands here   

  }

</script>

</head>

<body>

<input type="button" value="click me!" onclick="msg()" />

</body>

</html>


yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Be aware that some browsers may have JavaScript disabled, in which case the function call will fail. Always implement some sort of fallback plan, perhaps standard HTML, or maybe PHP, which cannot be interfered with in the browser, as it is server-side rather than client-side.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
for the purpose scripting is turned off, there is a <noscript> tag to use.

#7
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Yup, although there are not many no-script alternatives to the alert() function. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#8
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
But it gives the opportunities to alter the html code depending on scripts or not at least, maybe some other arrangements could be done instead.

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Perhaps a simple HTML message instead of a popup. Many websites use JavaScript (especially in AJAX) so it doesn't make sense to disable it.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#10
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Many people disable it due to security based reasons. You could also set a script up that checks to see if JavaScript is disabled. If it is show a message it is required to view the site, if it is enabled, just redirect to the normal JavaScript page.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#11
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts

Brandon W said:

Many people disable it due to security based reasons. You could also set a script up that checks to see if JavaScript is disabled. If it is show a message it is required to view the site, if it is enabled, just redirect to the normal JavaScript page.

That's what the <noscript> tag is used to. as the <noframes> tag if a browser shouldn't support frames.

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts

Brandon W said:

Many people disable it due to security based reasons.

JavaScript is a basic and largely integral part of web design. To disable it is like using a pneumatic drill to crack open a nut.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums