.= 'tag.htm'; break; case 'flag': $pre .= $default_pre .= 'flag.htm'; break; case 'my': $pre .= $default_pre .= 'my.htm'; break; case 'my_password': $pre .= $default_pre .= 'my_password.htm'; break; case 'my_bind': $pre .= $default_pre .= 'my_bind.htm'; break; case 'my_avatar': $pre .= $default_pre .= 'my_avatar.htm'; break; case 'home_article': $pre .= $default_pre .= 'home_article.htm'; break; case 'home_comment': $pre .= $default_pre .= 'home_comment.htm'; break; case 'user': $pre .= $default_pre .= 'user.htm'; break; case 'user_login': $pre .= $default_pre .= 'user_login.htm'; break; case 'user_create': $pre .= $default_pre .= 'user_create.htm'; break; case 'user_resetpw': $pre .= $default_pre .= 'user_resetpw.htm'; break; case 'user_resetpw_complete': $pre .= $default_pre .= 'user_resetpw_complete.htm'; break; case 'user_comment': $pre .= $default_pre .= 'user_comment.htm'; break; case 'single_page': $pre .= $default_pre .= 'single_page.htm'; break; case 'search': $pre .= $default_pre .= 'search.htm'; break; case 'operate_sticky': $pre .= $default_pre .= 'operate_sticky.htm'; break; case 'operate_close': $pre .= $default_pre .= 'operate_close.htm'; break; case 'operate_delete': $pre .= $default_pre .= 'operate_delete.htm'; break; case 'operate_move': $pre .= $default_pre .= 'operate_move.htm'; break; case '404': $pre .= $default_pre .= '404.htm'; break; case 'read_404': $pre .= $default_pre .= 'read_404.htm'; break; case 'list_404': $pre .= $default_pre .= 'list_404.htm'; break; default: $pre .= $default_pre .= theme_mode_pre(); break; } if ($config['theme']) { $conffile = APP_PATH . 'view/template/' . $config['theme'] . '/conf.json'; $json = is_file($conffile) ? xn_json_decode(file_get_contents($conffile)) : array(); } !empty($json['installed']) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . ($id ? $id . '_' : '') . $pre; (empty($path_file) || !is_file($path_file)) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . $pre; if (!empty($config['theme_child']) && is_array($config['theme_child'])) { foreach ($config['theme_child'] as $theme) { if (empty($theme) || is_array($theme)) continue; $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . ($id ? $id . '_' : '') . $pre; !is_file($path_file) and $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . $pre; } } !is_file($path_file) and $path_file = APP_PATH . ($dir ? 'plugin/' . $dir . '/view/htm/' : 'view/htm/') . $default_pre; return $path_file; } function theme_mode_pre($type = 0) { global $config; $mode = $config['setting']['website_mode']; $pre = ''; if (1 == $mode) { $pre .= 2 == $type ? 'portal_category.htm' : 'portal.htm'; } elseif (2 == $mode) { $pre .= 2 == $type ? 'flat_category.htm' : 'flat.htm'; } else { $pre .= 2 == $type ? 'index_category.htm' : 'index.htm'; } return $pre; } ?>javascript - How to get the <input>'s value? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get the <input>'s value? - Stack Overflow

programmeradmin1浏览0评论

How do I get the <input>'s Value

  1. I'm trying to make a page viewer through the iframe, so. I have searched up some things to help. But nothing has correctly done something to help. I've tried

Codes I used that didn't work.

Found on W3Docs, I used this portion of a code...

function getInputValue() {
  // Selecting the input element and get its value 
  let inputVal = document.getElementsByClassName("inputClass")[0].value;
  // Displaying the value
  alert(inputVal);
}
<input type="text" placeholder="Type " id="inputId" class="inputClass">
<button type="button" onclick="getInputValue();">Get Value</button>

How do I get the <input>'s Value

  1. I'm trying to make a page viewer through the iframe, so. I have searched up some things to help. But nothing has correctly done something to help. I've tried

Codes I used that didn't work.

Found on W3Docs, I used this portion of a code...

function getInputValue() {
  // Selecting the input element and get its value 
  let inputVal = document.getElementsByClassName("inputClass")[0].value;
  // Displaying the value
  alert(inputVal);
}
<input type="text" placeholder="Type " id="inputId" class="inputClass">
<button type="button" onclick="getInputValue();">Get Value</button>

It didn't properly alert the value of the input.

I also tried this, its supposed to have a variable inside of a function that I can simply put inside a button's onclick

var input = document.getElementById("input_id").value;

this also failed in return. nothing happened when I put it inside of a button.

Additional

Is there any source I can find things like this?

Share Improve this question edited May 14, 2021 at 21:44 j08691 208k32 gold badges269 silver badges280 bronze badges asked May 14, 2021 at 21:26 TheodoreTheodore 3031 gold badge3 silver badges15 bronze badges 10
  • What do you mean by "make a browser through the iframe"? If you're trying to access an input in a different frame/iframe, you won't be able to – Codebling Commented May 14, 2021 at 21:33
  • I didn't mean a "browser through iframe". I meant something where you can view pages throught the input. like wear-a-mask.ml or something. @Codebling – Theodore Commented May 14, 2021 at 21:35
  • var input = document.getElementById("inputId").value; (not input_id) – Kinglish Commented May 14, 2021 at 21:36
  • @Kinglish input_id was the Id of the input. – Theodore Commented May 14, 2021 at 21:38
  • 2 I pasted the code you claimed doesn't work into a snippet and it appears to work just fine. You're also causing some confusion because you claim getElementById("input_id") doesn't work but in your example the ID is inputId – j08691 Commented May 14, 2021 at 21:44
 |  Show 5 more ments

4 Answers 4

Reset to default 2

The best way to get the value of an input is by making a form:


    <form class="my-form">
        <input type="text" placeholder="Type " name="my-input">
        <button>Get Value</button>
    </form>

    <script>
        let form = document.querySelector(".my-form");

        form.addEventListener("submit", function (e) {
        e.preventDefault() // This prevents the window from reloading
        
        let formdata = new FormData(this);
        let input = formdata.get("my-input");

        alert(input);
        });
    </script>

That's the best way of geting data from inputs. You simply put the values of the form with new FormData(), and then you get the input values with formdata.get("input_name")

Like @Kinglish said, you made a typo when using getElementById.

 <input type="text" placeholder="Type " id="inputId" class="inputClass">
<button type="button" onclick="getInputValue();">Get Value</button>
<script>
  function getInputValue() {
    let inputVal = document.getElementById("inputId").value;
    alert(inputVal);
  }
</script>

It should be "inputId", not "input_id".

I dont get why there is a '[0]' in between the objects..maybe this can help you. Declare the variable first and then use it.

<input id="numb">
<button type="button" onclick="myFunction()">Submit</button>

function myFunction() {
  var x;
  x = document.getElementById("numb").value;
}

To use values entered in input tag use the following code. In following code value entered in input tag is pushed in the array named as myLead `

let inputBtn = document.querySelector("#input-btn")
let myLead = [];
const inputEl = document.getElementById("input-el");





 inputBtn.addEventListener("click", function(){
        myLead.push(inputEl.value);//here value of input field is pushed in array
        console.log(myLead)
        })

`

发布评论

评论列表(0)

  1. 暂无评论