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

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

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>

<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">

    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}`);
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
Help us understand the problem. What are the problem?