ria
ria

Reputation: 31

passing the input value of search bar as a parameter in button onclick

How can I pass the value entered by user in the search bar with the link in the button.

<form>

<input type="text" id="search" class="st-search-input search-field" value="abc"/>

<button type="submit" onclick='window.open("test4?abcd=\"search.value\"");'>Submit</button>
</form>

Upvotes: 0

Views: 3185

Answers (1)

Diana
Diana

Reputation: 445

<form>
    <input type="text" id="search" class="st-search-input search-field" value="abc"/>
    <button type="button" onclick='javascript: window.open("test4?abcd="+ document.getElementById("search").value);'>Submit</button>
</form>

OR

<form action="test4" target="_blank">
    <input type="text" name="abcd" value="abc">
    <button type="submit">Submit</submit>
</form>

Upvotes: 1

Related Questions