Help us understand the problem. What is going on with this article?

思い付きコード(後日解説)

More than 1 year has passed since last update.
<select name="select" id="sample" onchange="SendAjax(this);">
    <option value="user_name1">user1</option>
    <option value="user_name2">user2</option>
    <option value="user_name3">user3</option>
</select>

<input type="text" name="username" id="user_name1" value="name1">
<input type="text" name="username" id="user_name2" value="name2">
<input type="text" name="username" id="user_name3" value="name3">

<script>
    document.getElementById("user_name1").style.display = "none";
    document.getElementById("user_name2").style.display = "none";
    document.getElementById("user_name3").style.display = "none";

    function SendAjax(obj)
    {
        // objはselectタグ
        let idx = obj.selectedIndex;
        let value = obj.options[idx].value // value
        let text = obj.options[idx].text; // apper text

        const txt1 = document.getElementById("user_name1");
        const txt2 = document.getElementById("user_name2");
        const txt3 = document.getElementById("user_name3");

        if(value != txt1.id || value != txt2.id || value != txt3.id)
        {
            txt1.style.display = "none";
            txt2.style.display = "none";
            txt3.style.display = "none";
        }
        if(value == txt1.id)
        {
            txt1.style.display = "block";
        }
        if(value == txt2.id)
        {
            txt2.style.display = "block";
        }
        if(value == txt3.id)
        {
            txt3.style.display = "block";
        }

        console.log(`TEXT: ${text} / VALUE: ${value}`);
        console.log(`txt_ID1: ${txt1.id}`);
    }
</script>   
keye
会社で働いていますが、軽いタスクならフリーランスとして受けれるので仕事の依頼はメールを通じてご連絡していただける嬉しいです。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした