tags:

views:

67

answers:

1
var macs = {
    getMacAddress : function()
    {
        document.macaddressapplet.setSep( "-" );
        document.write( "Mac Address = " + document.macaddressapplet.getMacAddress() );
    }

how do i call this function and display out in the website?

this doesn't seems working..

<script type="text/javascript">
    document.write(mac.getMacAddress());
</script>

Anyone help?

+3  A: 

Just use macs.getMacAddress();

The function doesn't return anything. It simply writes to the document. If you want it to return the string, replace document.write with return when you define macs.

Also, note that calling document.write after the page is loaded will overwrite the current page (because it implies document.open). If you need to append to the document after it's loaded, use the DOM or innerHTML.

Anonymous
Thanks...if i want to display the mac address on that page itself, what should i do?Is there any example for me to read up? or do you have any sample for me?
kennedy
If you're doing this after page load, the simplest way is to have an element with a unique id, eg `<span id="macaddress"></span>`, and fill its contents in script: `var foo = document.getElementById("macaddress"); foo.appendChild(document.createTextNode(macs.getMacAddress()));`, where that function returns the string (`return "Mac Address = " + ...`). If you need to overwrite it later, you can do `foo.removeChild(foo.firstChild);` and then append more.
Anonymous
okay, got it. Thanks...Since i'm able to display out the data, how do i save it into mysql database?
kennedy
If you're using a regular web page with standard web permissions (no way to write to disk or do cross-domain requests), you can put that value into a form input (eg, `<input type="text" name="foo" id="bar">`, `document.getElementById("bar").value = macs.getMacAddress();`) and then have the user submit the form or submit it with script (`formelement.submit();'`).
Anonymous
its not a input, the system will automatically display the data in the web page..Would you be good enough to do one example for me?
kennedy
The simplest way to send this data from the browser to the serve is by submitting a form containing inputs containing the data to send.
Anonymous
how do i do that?
kennedy