mulder
06-22-2012, 09:08 PM
Hey all!
I have a search function as outlined below...
<script>
function subMit(){
val=document.getElementById("num").value
location.href="/search/result.php?id="+val; title="Search";
}
</script>
<form name="form1" action="" method="post">
<input type="text" id="num" value="">
<input type="button" value="Search" onclick="subMit()"/>
</form>
My problem is I would like to add 2 radio buttons to the search, the only code I can find is the one set out below..
<script type = "text/javascript">
function setAction() {
var actionVal;
if (document.myForm.rad1[0].checked) {
actionVal = "/search/result.php?id=";
}
else if (document.myForm.rad1[1].checked) {
actionVal = "otherpartofsite.com/search.php";
}
document.myForm.action = actionVal;
}
</script>
<form name = "myForm" method="post" >
<input type="radio" name="rad1" value="forum" checked> Forum
<input type="radio" name="rad1" value="blog"> Blog
<input name="search" size="20" maxlength="25" type="text">
<input name="Submit" type="submit" value="Search!" onclick = "setAction()">
</form>
I have tried to "merge" these two scripts together but to no avail - and as both buttons have an "onclick" event I cannot keep them separate..
Is there a way to make this into 1 function with 1 search box?
thanks in advance
I have a search function as outlined below...
<script>
function subMit(){
val=document.getElementById("num").value
location.href="/search/result.php?id="+val; title="Search";
}
</script>
<form name="form1" action="" method="post">
<input type="text" id="num" value="">
<input type="button" value="Search" onclick="subMit()"/>
</form>
My problem is I would like to add 2 radio buttons to the search, the only code I can find is the one set out below..
<script type = "text/javascript">
function setAction() {
var actionVal;
if (document.myForm.rad1[0].checked) {
actionVal = "/search/result.php?id=";
}
else if (document.myForm.rad1[1].checked) {
actionVal = "otherpartofsite.com/search.php";
}
document.myForm.action = actionVal;
}
</script>
<form name = "myForm" method="post" >
<input type="radio" name="rad1" value="forum" checked> Forum
<input type="radio" name="rad1" value="blog"> Blog
<input name="search" size="20" maxlength="25" type="text">
<input name="Submit" type="submit" value="Search!" onclick = "setAction()">
</form>
I have tried to "merge" these two scripts together but to no avail - and as both buttons have an "onclick" event I cannot keep them separate..
Is there a way to make this into 1 function with 1 search box?
thanks in advance