Hi there

I am setting up a text search with 3 search buttons to allow 3 different searches from the one text box. Each search has different values for the 2 hidden elements. So far I've got the 3 submit buttons working with the below code but I can't figure how to get the hidden values to be inserted. For each of the 3 different submits I need to tell javascript what the 2 hidden values are. Can anyone help me?

<SCRIPT language="JavaScript">
function OnSubmitForm()
{
	if(document.pressed == 'questions')
	{
		document.myform.action ="/search.php"
	    
   }
   
   
	else
	if(document.pressed == 'rankings')
	{
		document.myform.action ="news/search.php";
		 
	}
	else
	if(document.pressed == 'courses')
	{
		document.myform.action ="forum/search.php";
		 
	}
	return true;
}
</SCRIPT>
<FORM name="myform" method="GET" onSubmit="return OnSubmitForm();">
<input name="query" id="query" type="text" size="40" />

<input type="hidden" name="hidden1" value = "" />
<input type="hidden" name="hidden2" value = "" />

<INPUT TYPE="SUBMIT" name="submit" onClick="document.pressed=this.value" VALUE="questions">
<INPUT TYPE="SUBMIT" name="submit" onClick="document.pressed=this.value" VALUE="rankings">
<INPUT TYPE="SUBMIT" name="submit" onClick="document.pressed=this.value" VALUE="courses">

</FORM>

Thanks a lot for any advice

you don't need to insert any hidden fields as such, just set the value. if this is to be filled when you submit the form, then make use of the onclick event and set the element (your input field) value.

e.g. document.getElementById().value = "blah"

Don't just copy and paste the code, it's just there to give you the idea.

Hi sillyboy

thanks a lot for the reply but I'm afraid I am a newbee to javascript and don't really understand what you suggest.

Could you give me some more details of how I can make it work? thanks a lot!

ok, well from my understanding you want to set the value of hidden1, hidden2 depending on which submit button is pressed. you already have the onclick event, so inside the event you want to execute some javascript which will populate the values for you.

e.g. onclick=setValues()

if you do this, you obviously need a corresponding function setValues defined, which should do something like i posted in my preview reply.

does that make more sense?

got it, thanks a lot for your help sillyboy!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.