I'm pretty new to jQuery and I've been given a task I really have no idea how to complete. Here's the situation:
I have a form as follows:
Code:
<form action="search.php" method="get" id="cse-search-box">
<input type="text" name="q" size="31"/>
<select name="category">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
<select name="contributors">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
<input type="submit" name="sa" value="Search" />
</form>
The form is used to submit a query to google site search. The input field 'q' is the main search query.
I need to combine the user's choices in the 'category' and 'contributors' fields into one variable, named 'as_q', and insert this into a form field on submission.
Thanks in advance for any help
<script>
$('#cse-search-box').bind('submit', function(){
var category = $('[name=category]').val();
var contributors = $('[name=contributors]').val();
$('[name=q]').val(category+' '+contributors);
});
</script>
Have this piece of script after the <form>
is declared (it's html, i'm not very sure if it is appropriate to use declare)