0

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

3 Answers 3

2

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

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

2 Comments

you are a lifesaver! I wish I asked sooner. Thank you so much!
@elenanincevic Glad to save your time :) Mark the green tick if you found helpful.
1

Try with placeholder like

<input value="" placeholder="Enter Keywords" type="text" name="keyword" id="key" onChange="bq()">

Comments

1

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>

2 Comments

You are right. It works on ie10, but not older. Thank you!! I will try it your way.
I am not sure why, but this solution is not working on the form above. I am not as good with JS, but I assume it has to do with the onchange function that is already applied to each select and input box. If you have a quick fix on that, let me know. Thank you.

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.