0

I want to make an html where you enter a keyword.

<html>    
  <head>
    <title>Options</title>
  </head>    
  <body>
    <input name="Keyword" type="text">
    <input name="Submit" type="submit" value="Submit">
  </body>    
</html>

I want to use that keyword in a javascript between these quotations

var shoeName = "";

This is for a chrome extension so on the options page I want to enter a keyword, submit it and have it automatically put it into the javascript

2
  • What about to provide an id too and to use GetElementById()? Commented Dec 23, 2013 at 8:49
  • set a id for the input text like this <input id="keyText" name="Keyword" type="text"> & can refer the same in js like this <script>var shoeName = document.getElementById("keyText").value; </script> Commented Dec 23, 2013 at 8:52

3 Answers 3

1

You can do it by setting an ID for the element and accessing the element using the ID.

HTML:

<html>    
    <head>
        <title>Options</title>
    </head>    
    <body>
        <input id="keyText" name="Keyword" type="text">
        <input name="Submit" type="submit" value="Submit">
    </body>    
</html>

JS:

<script>
    var shoeName = document.getElementById("keyText").value;
</script>

Happy coding.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't know why this isn't working.. I want to make a chrome extension that has an options page where you enter a keyword:
Well bro, thats seems like a new Question, since you have already created a Question on SO for this, i will check in it, meanwhile lets close this Question as it has served its purpose. you can close this Question by ticket this solution as a answer.
0

You can get the input value using

shoeName =  $("input[name='Keyword']").val(); // if you can not add id

if id can be added just do

$('#inputid").val()

or if you want data on form submit do

<form name="myForm" id="testForm" method="POST" action="send.php"> 
<input name="Keyword" type="text">
<input name="Submit" type="submit" value="Submit"
</form>

var shoeName = "";

$("form[name='myForm']").submit(function(){
    shoeName =  $("input[name='Keyword']").val()
 // other processing
});

2 Comments

OP was expecting a Pure JS implementation and not Jquery.
0

Try this:

var shoeName;

document.addEventListener('DOMContentLoaded', function() {

    document.getElementById('keyword').addEventListener('keyup', function() {
        shoeName = this.value;
    });

});

Every time text is added to the textbox, shoeName is being updated.

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.