-4

Heres my Code:

<form>
<input class="wrapped-input" type="text" id="blah blah" style="text-align:center" placeholder="(Enter your exact search term here)" name="exact_term" tabindex="5" required/>
</form>

I've ommitted a few things to make this form functional, however I would like to place double quotes AROUND any value the user enters into the html input field.

What's the best way to do this?

user3213028
  • 27
  • 2
  • 8

3 Answers3

1

I went under the assumption that you wanted to wrap what the user submits in quotes rather than manipulating the textbox itself.

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css">
        <script>
            $(document).ready(function() {
                $('#btnSubmit').click(function() {
                    var userInput = $('#blah-blah').val()
                    alert('User input: "' + userInput + '"');
                });
            });
        </script>
    </head>
    <body>
            <form>
                <input class="wrapped-input" type="text" id="blah-blah" style="text-align:center" placeholder="(Enter your exact search term here)" name="exact_term" tabindex="5" required/>
                <input type="submit" id="btnSubmit" value="Submit" />
            </form>
    </body>
</html>
random
  • 9,774
  • 10
  • 66
  • 83
fischgeek
  • 688
  • 1
  • 5
  • 18
0

You could use jQuery to manipulate the string before the form is submitted or you could just use string interpolation to add parentheses on the server side.

Daniel Bonnell
  • 4,817
  • 9
  • 48
  • 88
0

Here is a pure JavaScript version of what you want to do, because, well, screw jQuery.

var thing = document.getElementById('thing');


thing.addEventListener('keyup', function() {
    if (!/^\"/.test(thing.value)) {
        thing.value = '"' + this.value;
    }
});

thing.addEventListener('blur', function() {
    if (!/\"$/.test(thing.value)) {
        thing.value = this.value + '"';
    }
});
brian
  • 2,745
  • 2
  • 17
  • 33