-1

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

1
  • 2
    Show the code you are working with, not some generic example code. Commented Apr 19, 2015 at 20:23

1 Answer 1

0

Is this something you wish to achieve?

<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<button type="button"
     onclick="var the_id=document.getElementById('my_field').value;
        document.getElementById('demo').innerHTML=
        document.getElementById(the_id).innerHTML;">
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>

</body>
</html> 
7
  • 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
    Commented Apr 19, 2015 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
    Commented Apr 20, 2015 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
    Commented Apr 20, 2015 at 23:41
  • So, if you replace "not working" with "working" this will work. I don't know where email is stored actually.
    – brownian
    Commented Apr 21, 2015 at 3:48
  • instead of 'not working' i want it to show the email address that was enter inside the custom field
    – Alex DS
    Commented Apr 21, 2015 at 6:21

Your Answer

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

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