Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 991043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:02:36+00:00 2026-05-16T06:02:36+00:00

This script of mine has a function, which is not working the way, I

  • 0

This script of mine has a function, which is not working the way, I want it to. Take a look at the script, the function is called display_Value():

<html>

    <head>
        <title>JavaScript</title>
        <!--Scripts-->
    <script type="text/javascript">
    <!--

    function noValue(id) {  
        var _value = document.getElementById(id).value;
        if (_value == "Skriv dit navn her") {
            document.getElementById(id).value='';
        }
    }

    function changeValue(id) {
        var _value = document.getElementById(id).value;
        if (_value == "") {
            document.getElementById(id).value='Skriv dit navn her';
        }
    }

    function display_Value() { 
        var val = document.getElementById("txt").value; 
        if (val != "Skriv dit navn her" && val != "") { 
            document.getElementsByName("placeholder").innerHTML = val; 
            document.getElementById("hidden").style.visibility="visible"; 
            destroy("destroy") 
        } 
    }

    function destroy(id) {
        var d = document.getElementById(id);
        d.parentNode.removeChild(d);
    }

    //-->
    </script>
</head>

<body>

    <div id="destroy">
    <input type="text" id="txt" value="Skriv dit navn her" onFocus="noValue('txt')" onBlur="changeValue('txt')">
    <input type="button" onClick="display_Value()" value="Click me" />
    </div>

    <div id="hidden" style="visibility: hidden">
    <p>Hello. Your entered value is: <span name="placeholder"></span> and it is repeated below</p>
    <span name="placeholder"></span>
    <span name="placeholder"></span>
    </div>

The functions noValue() and changeValue() makes the original value disappear on focus and come back if the field is empty on blue. That part works. When the button is clicked, the value in the text box is supposed to be displayed in the <span name="placeholder">-tags. That’s not happening. The hidden text which is hidden with <div style="visibility:hidden"> is shown, as I want it to, but the value is not displayed. The form gets destroyed, just as I want to. Where have I made a mistake? 🙂

Ps.: If you are wondering what “Skriv dit navn her” means, it means “Write your name here” in danish.

EDIT

I isolated parts of the code once again. I found out, that if I replace getElementsByName("placeholder").innerHTML; with getElementById("placeholder").innerHTML; and assigns the first <span> with and ID=”placeholder” the value is displayed in that particular <span>.This is, however, not exactly what I wanted. I wanted the value to be displayed in all 3 of the placeholders – how?

ANOTHER EDIT

I know it is possible to make this script work by assigning ID’s to all of the placeholder; I’m not interested in that. I would like the function to display the value in all of the placeholders in as little text as possible and without repeating. I think this is called DRY / DIE 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:02:36+00:00Added an answer on May 16, 2026 at 6:02 am

    Replace your display_Value function with this:

    function display_Value() { 
        var val = document.getElementById("txt").value; 
        if (val != "Skriv dit navn her" && val != "") { 
            document.getElementsByName("placeholder").innerHTML = val; 
            document.getElementById("hidden").style.visibility="visible"; 
            destroy("destroy") 
        } 
    } 
    

    You were taking the value of the placeholder, not a reference to it. So the value wasn’t going anywhere. You need to assign it directly to the innerHTML of the placeholder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've heard mixed responses about this working/not working . Mine happens to not work
This script saves the files as /home/name/main/all my files and stuff . I want
I use this script in two different servers: function curlGetFileInfo($url, $cookies=default){ global $_config; $ch
i use this script to load content of some div, inside another div: $(function()
As of Chrome 19.0.1084.46, there is an extension of mine that has stopped working
i have this simple script of a popunder window: function loadpopunder(){ win2=window.open(popunder,,winfeatures) win2.blur() window.focus()
Hi I'm tearing my hair out right now, I found this script online which
I am working with a company who has made a script to send over
This script cannot find bannersize unless I write <div id=bannersize></div> before the javascript. The
This script works fine on single click but on double click it shows both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.