We help IT Professionals succeed at work.

Form / Post Action suing combo box

superabbe
superabbe asked
on
Hello everybody...

My friend Babban asked this question but didn't got any answeres. Im curious myself.

Can I by using a a form, combobox and a send button post different actions letting the combo box control the action?

Let say my combobox have 3 values.

"Projects" (action=page1.asp)
"Programs" (action=page2.asp)
"Production" (action=page3.asp)

Is this possible in some way. This could be useful I think. Some trick or a solution that reminds of this?

Rgrds

Comment
Watch Question

CERTIFIED EXPERT
Commented:
I think this would do it:

<form name="frm">

<select name="destination">
<option value="page1.asp">Projects
<option value="page2.asp">Programs
<option value="page3.asp">Production
</select>
<br>
<input type="button" value="Go" onclick="document.frm.action=document.frm.destination.value;document.frm.submit();">

</form>

Author

Commented:
Hi.
Almost what I want.
Wait..I post my code here. I use SQL tabels.
I have added one field to my table named 'DestinationPage'.
How can I implement that to my code/combobox, that field should hold the post action information (example: page1.asp). It shall be hidden.

How can I then Post the value as I do here and also post the action to the destination in field 'DestinationPage'?

<form name="Selecthelpdesk">
  <table border="0">
    <tr>
      <td>HELPDESK v 0.01</td>
    </tr>
    <tr>
      <td class='headline'>Select helpdesk<br>
        <select name="Group" size="1">
          <%
set remoteconn=server.CreateObject("ADODB.connection")
remoteconn.Open "Provider=SQLOLEDB.1;Driver={SQL  Server};SERVER=aa;DATABASE=Helpdesk;UID=sa;PWD=;"

SQLstmt = "SELECT * from tblAssignToGroup"
Set assign = remoteconn.Execute(SQLstmt)
selstring="selected"
While Not assign.EOF
Response.write "<option " & selstring & " value=""" & assign("AssignToGroupName") & """>" & assign("AssignToGroupName")& "</option>"
selstring=""
assign.movenext
wend
%>
        </select>
      </td>
    </tr>
    <tr>
      <td><b>
        <input type="button" value="Send" onClick="this.form.submit()" name="button">
        </b></td>
    </tr>
  </table>
</form>
CERTIFIED EXPERT

Commented:
Try these changes:

Response.write "<option " & selstring & " value=""" & assign("DestinationPage") & """>" & assign("AssignToGroupName")&
"</option>"

<input type="button" value="Send" onClick="this.form.action=this.form.Group.value;this.form.submit();" name="button">

Author

Commented:
But AssignToGroupName holds values like

AABB
BBAA
CCDD

That must be trigged on the 'destination page'...

?
CERTIFIED EXPERT

Commented:
Oh, ok. As long as the url:s don't contain a semicolon (;), these additional changes should do it:

<input type="hidden" name="Group">
<select name="GroupList" size="1">

<input type="button" value="Send" onClick="this.form.action=this.form.GroupList.value;this.form.Group.value=this.form.GroupList(this.form.GroupList.selectedIndex).text;this.form.submit();" name="button">
CERTIFIED EXPERT

Commented:
Eh, forget that about the semicolon. That was from a different solution I had in mind.

Commented:
<Script>

Function SomeFunction()
{
document.frm.action=document.frm.option.value;
document.frm.submit()
}
</Script>

<form name="frm" action=SomePage.asp>
<select name="option" OnChange=SomeFunction()>
<option value="page1.asp"> Option 1
<option value="page2.asp">Option 2
<option value="page3.asp">Option 3
</select>
</form>


Just check it for grammer ... this is the solutuion you needd.... but some small mistake of Comma and all may be there ... Alryte

Get Going

Mihir

CERTIFIED EXPERT

Commented:
Mihirl, yes, except you don't have a submit button. And if the user does not change the option, it does not go to the page of the default option. And superabbe needs the text of the options on the next page, that code doesn't do that.

Read the previous postings.

Author

Commented:
I think GreenGhost have a correct answere.

Author

Commented:
I think GreenGhost have a correct answere.

Commented:
mihirl, it is rude to lock up a question, especially when you are just repeating someone else's answer.

Author

Commented:
Someone else was first.

Commented:
Hey ! Buddy ... ity was by mistake .. i had no intentions of selecting answetr ....anyways ....

Thanx

Mihir

Explore More ContentExplore courses, solutions, and other research materials related to this topic.