I am trying to create this button for a custom field that I have on my website

<button type="button"
        onclick="document.getElementById('demo').innerHTML = Date()">
        Click me to display Date and Time.</button>

The thing is, when i hit the button to show me the input from a custom field that I have on my wordpress site. I put the name on the field instead of 'Date()' and the id of the div i have but nothing happens. Problem is i don't know what code should I write in order to do just that.

Update(based on brownian): So, this is an infographic that explains better what i need: what i want to achieve

how it looks the custom field element

  • 2
    Show the code you are working with, not some generic example code. – Nicolai Apr 19 '15 at 20:23

Is this something you wish to achieve?

<!DOCTYPE html>

<h1>My First JavaScript</h1>

<button type="button"
     onclick="var the_id=document.getElementById('my_field').value;
Click me to display some other string.</button>

<p id="demo"></p>

<input id="my_field" type="text"></a>

<div id="someother">Hi there!</div>

  • if instead of text i put the id of the field and instead of id="text" i replace it with id="my_field" it still doesn't show anything :/ – Alex DS Apr 19 '15 at 21:49
  • If instead you explain what you want to achieve --- not to break... ,) Ok, I've updated my answer --- is that what you'd like to achieve? – brownian Apr 20 '15 at 7:06
  • Brownian, I just updated my question with a graphic explaingin better what I am trying to get. Hope it explains better. PS: I have tried you updated code, but no luck. I am not sure what do I do wrong. I have written the code in the picture – Alex DS Apr 20 '15 at 23:41
  • So, if you replace "not working" with "working" this will work. I don't know where email is stored actually. – brownian Apr 21 '15 at 3:48
  • instead of 'not working' i want it to show the email address that was enter inside the custom field – Alex DS Apr 21 '15 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.