Ok, got it working with:
HTML Code:
<html>
<script type="text/javascript">
function doSearch(){
doSub=true;
if(document.getElementById('company').checked){
//change the action value of the first <form>
document.getElementsByTagName('form')[0].action="/searchName.php";
if(document.getElementById('city_search').selectedIndex==0){
alert("Please select city first!");
document.getElementById('city_search').focus();
doSub=false;
}
}
else{
document.getElementsByTagName('form')[0].action="/searchKeywords.php";
if(document.getElementById('get_searchword').value==""){
alert("Please enter category / company name for search.");
document.getElementById('get_searchword').focus();
doSub=false;
}
}
//submit the form
if(doSub===true){
document.getElementsByTagName('form')[0].submit();
}
}
</script>
<body>
<form action="srch/searchkey.php?id="$_POST['get_searchword']"&title="$_POST['city_search']"" method="POST" name="frm" id="frm">
<div id="divSearbar" class="search_bar" style="height:78px;">
<div id="divCity" class="search_element">
<div class="search_label"><b>City:</b></div>
<div class="clear"></div>
<div >
<select name="city_search" id="city_search" class="input_city">
<option value="">Select City</option>
<option value="1">City 1</option>
<option value="2">City 2</option>
<option value="3">City 3</option>
<option value="4">City 4</option>
<option value="5">City 5</option>
</select>
</div>
</div>
<div class="search_element">
<div id="cat_comp" class="search_label display"><b>Search By</b>
<input type="radio" name="comp_cat" class="radiobtn" id="company" />
Company / Name
<input type="radio" name="comp_cat" class="radiobtn" id="category" checked="true" tabindex="1" />
Product / Services </div>
<div id="comp" class="search_label hidden"> <b>Search By</b> Company / Name </div>
<div class="clear"></div>
<input id="get_searchword" name="get_searchword" class="input_search" value="" />
<div class="clear"></div>
</div>
<div class="search_element">
<div id="divAreaLabl" class="search_label"><b>Which part of ?</b></div>
<div class="clear"></div>
<div id="divAreaVal">
<input id="get_val" class="input_area">
</div>
<div class="clear"></div>
<div id="area_part_main" class="search_label" style="overflow:hidden;height:30px;text-align:left;"></div>
</div>
<div style="float:left; padding-left:6px; padding-top:8px;">
<input type="button" class="Gobtn" value="Go" onClick="javascript:doSearch()"/>
</div>
</div>
</form>
</body>
</html>
You had a spelling error in doSearch:
HTML Code:
document.getElementsByTagName('form')[0].action="/"searchKeywords.php;
should have been
HTML Code:
document.getElementsByTagName('form')[0].action="/searchKeywords.php";
This was rendering the whole function invalid, and thus was ignored by the browser.
Furthermore, I have integrated the check in the doSearch(), no reason to keep them separated, and I rewrote them to use the DOM methods to access the elements.
The formname.fieldname way is deprecated.
By the way, in the case of a drop down, you cannot use the dropdown.value way of an input filed to get the value.
You must use:
Code:
dd=document.getElementById('mySelectId');
value=dd.options[dd.selectedIndex].value
a select having an array of options, you have to point to the value of that option based on the selected index position of the drop down.
The dropdown.value method works only in internet explorer, as far as I know.
May I ask with what browser do you tested it ?
If you didn't use firefox, you should.
Add the firebug extension, and you would have seen every errors pointed to the right line, as for every warning about deprecated javascript calls.