View Full Version : Help: Click button, set contents, then submit

10-20-2003, 10:18 PM
Can anyone help me - this is fairly simple but I'm not good with syntax yet... I have a regular button that, when clicked, should set the contents of a search text field called "keywords" to the string "sold", and then click the associated submit button. Not sure where to add the code to get it to submit, and also the "sold" isn't even going into the field. I'd like to do this invisibly, but don't know how. Please help me? Thank you Mary

<input type="button" onClick="document.srch.keywords.value="sold" name="search_request_button" value="Search Our Sold Properties" >

10-20-2003, 10:25 PM
First, you have quotes within quotes.



Roy Sinclair
10-20-2003, 10:28 PM
<input type="button" onClick="this.form.keywords.value='sold';this.form.submit();" name="search_request_button" value="Search Our Sold Properties" >

This should work, your original had mismatched quote marks and needed the submit call. I abstracted the reference to the containing form so it won't haurt the code if the name of the form is changed and the original reference was using an IE proprietary reference to the form while the changed reference to the form should work with all browsers.

10-20-2003, 10:30 PM
You are the greatest!!!!!!!!!!!!!!!!! Thanks so much!!!!!!!

10-20-2003, 10:49 PM
This code worked beautifully!!! Is it outside the scope of Javascript to avoid showing the word "sold" as it populates the search field - in other words, to make it invisible somehow since they are just clicking a button? Yes? Yes?

<input type="button" onClick="this.form.keywords.value='sold';this.form.submit();" name="search_request_button" value="View Recently Sold Properties" >

10-21-2003, 12:19 PM
If you don't want to show the field keywords, then why not make it hidden?

<input type="hidden" name="keywords">