Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two buttons on one page

Status
Not open for further replies.

TRACEYMARYLAND

Programmer
May 21, 2004
370
US
hi there i have a form
<form name="form1" method="post" action="form_entry_update.asp">

But i want to add two buttons...

One button will be called SEARCH...and the other will be UPDATE

Now if i select UPDATE i want it to actually go and do the
form_entry_update.asp

If i select SELECT i want it to call another page search.asp will all the form values.

Cannot figure out how to put two buttons with two different things on a page
 
<input type=submit value="Update">

<input type=button onClick="document.location='search.asp'" value="Search">

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
One little question...will the button for search
pass all the values from the form to the search.asp

so if im in search.asp i can still read
request.form("field")

Thanks
 
You would just need to modify mwolf's code slightly to submit the form after changing its action.
Code:
<input type=submit value="Update">

<input type=submit onClick="form1.action='search.asp'" value="Search">
Have to admit, though, that I typically will create a small client-side function that will set the form action independently and then submit from that same function. But to each his own...

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Another option is to use server.transfer() on the server-side to pass all of the values from form_entry_update.asp to search.asp

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Hi

I would do this on the server like so...

Code:
<%
' See if the form is submitted
if request("search") OR request("update") <> "" then
' Get our fields
For ix = 1 to Request.Form.Count
    fieldName = Request.Form.Key(ix)
    fieldValue = Request.Form.Item(ix) 
    Session(fieldName) = fieldvalue
Next
'see which button was pressed
If Request("Update") then
   url = "update.asp"
else
   url = "search.asp"
end if
end if
%>
You can then use them as session variables or reverse the code above to output them as form fields etc again.

Not tested but fundamentally it should be ok...... O & OE :p

Hope that this helps

Thanks


Glen
Conception | Execution
 
you can use buttons in the same form and use javascript to alter the action page variable on the form.

have a look at this function below, whihc i use for postcode checking, if you click on postcode check it does a post back to itself

Code:
	function do_postcode_checkup1(form) {
	
			if (form.cust_postcode.value == "") {
				// do nothing
				alert('You have not entered a postcode');
			}
			else {
			
			form.cust_post_check.value = "1"
			form.action="booking.asp"
			form.submit();
			
			}
	}

Note the form.action="" setting.
 
Thinking hard here.

I seen the server.transfer() before but never managed to get it to work...

Maybe i investigate that a little more.

Cheers All

 
mwolf00 server.transfer

lets say im in page1.asp

User fills in text1 and text2

Search....if user selects button search i can do a
if request("Submit") = "Search" then
server.transfer("search.asp")
end if
So in search.asp i see all the variables....

Is that correct
 
yes - server.transfer sends the request object from the first page (form_entry_update.asp) to the second (search.asp) so all of the form fields can be accessed.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
i'm a little lazy when coding sometimes, little more thinking sometimes, but in the end makes it easier.. this is how i handle one of my multi-button pages.. depends on JS tho.

Example a search text box, buttons for search DB , search FileSystem, or whatever.

Firstly so the page layout isn't all goofy because of form tags:
<style>
FORM {margin:0;
margin-top:0;
margin-bottom:0;
margin-left:0;
margin-right:0;}
</style>

i would have the layout like this :
<form name="EntryForm"> 'note no method, target, or action
<input type="text" name="SearchBox">
</form>

Then the seperate buttons:
<form name="SubmitOne" action="SearchFS.ASP" method="post" onsubmit="javascript:this.SearchVal = document.EntryForm.SearchBox;">
<input type="submit" value="Search FS">
<input type="hidden" name="SearchVal">
</form>

<form name="SubmitTwo" action="SearchDB.ASP" method="post" onsubmit="javascript:this.SearchVal = document.EntryForm.SearchBox;">
<input type="submit" value="Search DB">
<input type="hidden" name="SearchVal">
</form>

that way you dont have to modify the forms action target, or anything, you're just injecting the necessary values into the submit form from another.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
seems i forgot the .value on the JS portions in the samplecode :

<form name="SubmitTwo" action="SearchDB.ASP" method="post" onsubmit="javascript:this.SearchVal[red].value[/red] = document.EntryForm.SearchBox[red].value[/red];">

little bit different method of dealing with it, just trying to give some other options on the matter at hand :)

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top