Reputation: 83
Here is what I have:
<form method="get" action="" name="advsearch">
<input type="hidden" name="query" value="">
<div class="formelement-01">
<select name="product" size="1" onclick="bq()">
<option value="" selected="selected">Select Brand</option>
<option value="brand 1">brand 1</option>
<option value="brand 2">brand 2</option>
</select>
</div>
<div class="formelement-02">
<select name="cut" size="1" onchange="bq()">
<option value="" selected="selected">Select Product Type</option>
<option value="product 1">product 1</option>
<option value="product 2">product 2</option>
<option value="product 3">product 3</option>
</select>
</div>
<div class="formelement-03">
<input onfocus="if (this.value == 'Enter keywords') this.value = '';" value="Enter keywords" type="text" name="keyword" id="key" onChange="bq()">
</div>
<div class="formelement-04">
<input type="image" src="images/submit.gif" value="Submit" name="Submit" id="sbmit">
</div>
</form>
<script type="text/javascript">
function bq() {
document.advsearch.query.value = document.advsearch.cut.value + " " + document.advsearch.product.value + " " + document.advsearch.keyword.value;}
</script>
The form works fine, but if I do not replace the value "Enter keywords" with something else, it gets submitted along with the options I choose.
How do I prevent this specific value, "Enter keywords", from submitting? Please note, the form should be able to submit any other value, just not this one.
I hope there is somebody who can help with this.
Thank you in advance. Elena
Upvotes: 0
Views: 538
Reputation:
You can use the placeholder
property of input type but remember this placeholder property will not work on IE.
SO use the following code:
<form method="get" action="" name="advsearch" onSubmit="fun()">
add a function on form. Then use the following script.
<script type="text/javascript">
function fun() {
var ele = document.getElementById("key");
if(ele.value == "Enter keywords") {
ele.value = "";
}
return true;
}
</script>
Upvotes: 1
Reputation: 28763
Try with placeholder like
<input value="" placeholder="Enter Keywords" type="text" name="keyword" id="key" onChange="bq()">
Upvotes: 1
Reputation: 121998
I guess you need Html placeholder instead of doing old text validations.
<input type="text" name="mytextbox" placeholder="Enter keywords">
See here for examples and demo
Upvotes: 2