0

I have an old page created in clasic asp, contain a form, I am trying to submit the form using JavaScript function after checking the values available in the form.

HTML:

<form method="POST" action="vendorCheckDates.asp" name="Searchform" id="submit_Form">
    Select Type of Search: </b>
    <select size="1" name="Query" class="button">
        <option selected name="vNAME" value="vNAME"> Name</option>
        <option name="vNUM" value="vNUM"> Number</option>
        <option name="vEM" value="vEM">Email </option>
        <option name="vFAX" value="vFAX">Fax </option>
    </select>
    <b>:</b>
    <input type="text" name="hsearch" id="hsearch">
    <fieldset class="fieldset">
        <legend><strong>Type</strong></legend>
        <input type="radio" value="gov" name="tType" >Gov
        <input type="radio" value="gfos" name="tType">GFOS
    </fieldset>
    <input type="button" value="Search" name="hfind" Onclick="SubmitForm()">
</form>

The function

function SubmitForm() {
    var hsearch = document.all.submit_Form.hsearch.value;            
    var tType = document.getElementById('tType').value;            
    if ((hsearch = ! '') && (hsearch = ! null)) {               
        if ((tType = ! '') && (tType = ! null)) {
            document.all.submit_Form.submit();
        } else { alert("please select search type");}
    } else { alert("please write search criteria"); }
}

When I run the form the field hsearch is empty, but when I click submit the value will be true, its strange since I still didnt write anything in the input field hsearch, thats why the sels part in JavaScript function will not work

0

3 Answers 3

3

I think you are using wrong operator. it should be

 if ((hsearch != '') && (hsearch != null)) {               
        if ((tType != '') && (tType != null)) {
Sign up to request clarification or add additional context in comments.

Comments

0

You have to write hsearch != '' instead of hsearch = ! ''.

What you are doing is not checking for a value, but assigning a value that returns true.

hsearch = ! ''
=> hsearch = !''
=> hsearch = true
=> true

Comments

0

Instead of:

var hsearch = document.all.submit_Form.hsearch.value; 

Try:

var hsearch = document.getElementById('hsearch').value; 

You can always debug the value by putting an alert like:

alert(hsearch)

Comments

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.