Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@keye

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

<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>   
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
0
Help us understand the problem. What are the problem?