Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get HTML element value by JavaScript?

<div class="gallery_re_form">
  <form action="http://gall.dcinside.com/?/forms/comment_submit" method="post" accept-charset="utf-8" name="comment_write" id="comment_write" />
      <div style="display:none">
          <input type="hidden" name="ci_t" value="625752bb366f010c56e506e5d0f93822" />
      </div>
      <input type="hidden" name="ehqo_C" id="ehqo_C" value="spam_key" />
      <input type="hidden" name="spam_key" id="spam_key" value="rhkdrhgkwlak!!" />
      <input type="hidden" name="fb8f95190d2b70480acb309f91653d7e4416d4f99a0b67a0b866f06087fdec4588f68fe210675e74919d2ecc50e08f1fd6f75119" id="fb8f95190d2b70480acb309f91653d7e4416d4f99a0b67a0b866f06087fdec4588f68fe210675e74919d2ecc50e08f1fd6f75119" value="b9d3cc45576e30144d8f299fdc61356552989b3aba08238c811b1d3183a104cc2d1d3984af72c4f2eaa2738ca41819d05533731a" />
      <input type="hidden" name="service_code" value="21ac6e96ad152e8f15a05b7350a24759b5606fa191c17e042e4d0175735f4c61d63153c3ce7b4eb89b565a7f6a04ad0667df75f39625ab6fe0816d23f4bed5387546b52d6874b5c201e54df7b5db9187219b048cffc9ef8a106febabfba125eff122df732d9cc52fcaae8b11c42ff5f6fd5ef81901df4103827e7233615992141c180be76852634d53b60c6f911ccdfc762b3db554d8ee36528547bceede30697120c5291acb255a" />
      <br />
      <div class="re_input">
          <div>
              <ul>
                  <li>
                      <input type="text" name="name" id="name" class="re_name re_in" onfocus="this.style.background='#FFFFFF'" title="nickname" />
                  </li>
                  <li>
                      <input type="password" name="password" id="password" class="re_pw re_in" onfocus="this.style.background='#FFFFFF'" title="password" />
                  </li>
              </ul>
          </div>
      </div>
  </form>

I'm trying to rewrite google chrome extensions. I want to get #spam_key s #service_codes value in this HTML response.

I have not used JavaScript.

How can I get HTML element id (spam_key, service_code) and value by JavaScript?

like image 877
the pheonix Avatar asked Mar 10 '23 17:03

the pheonix


1 Answers

DOM has a document object , you can use it like this to get the HTML element what you want

document.getElementById("id")

Now to get value, just use value property of this element.

document.getElementById("id").value
like image 162
王吉志 Avatar answered Mar 19 '23 03:03

王吉志