4
<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?

3
  • Where are id = spam_key value and id = service_code ? Commented Mar 3, 2017 at 8:06
  • @Alexandru-IonutMihai Mistakes in formatting were hiding them from view. Should be fixed now. Commented Mar 3, 2017 at 8:10
  • 2
    Possible duplicate of How to get an input text value in JavaScript Commented Mar 3, 2017 at 8:14

5 Answers 5

5

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
Sign up to request clarification or add additional context in comments.

Comments

3

You want to retrieve the spam_key element and service_code element's values?

var spam_key = document.querySelector('#spam_key');
var service_code = document.querySelector('input[name=service_code]');

console.log(spam_key.value);
console.log(service_code.value);

You can learn more about selection element from javascript at here

Comments

0

You can get value of an HTML input element using:

var spam_key = document.getElementById('spam_key').value;
var service_code = document.getElementById('service_code').value;

Comments

0

Try this, It should give the value of spam_key

document.getElementById('spam_key').value;

4 Comments

Don't use both javascript and jquery.
Yup i was confused b/w val() and value .. now recheck and changed it @Alexandru-IonutMihai
@Ashu just a pointer, please check other answers before you post. Does you answer points or add something more to that other answer have addressed? If no, then your answer is just redundant.
@Rajesh I was answering when there were not any Answer
0

If you have jQuery included you can get it by following: $("#spam_key").val()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.