freginold on "Using forms and linking javascript to a button"

ساخت وبلاگ

Hello @xsimpson5-

To link a JavaScript function to the click of a button, you can use this attribute with your <button> element:

<button onclick="functionName();">

If you want to pass in parameters, you can do that in between the () after the function name. To obtain information from an HTML element such as a table, you can use:

document.getElementById('tableID').innerHTML;

and swap out tableID for the ID that you assigned to that table data element.

Similarly, you can use the same code to assign new data to an element, as in:

document.getElementById('tableID').innerHTML=newData;

If you are using a form, you might want to include the preventDefault() method in your function, to prevent the form from resetting the page when the user clicks the button.

You can see how to use the onclick= attribute by right clicking on the link you included for the poem reversal page and selecting "View Page Source" from the context menu. You can see more detail about using the preventDefault() method here.

- - , .

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 210 تاريخ : يکشنبه 25 بهمن 1394 ساعت: 11:26