Solved

Auto Submit on dropdown box

Posted on 2016-10-31
14
89 Views
Last Modified: 2016-10-31
I had this question after viewing Auto Submit on dropdown box.

Hi all, I have sucessfully used this, however on the same page I have a 2nd auto submit (ClientCurr) I would like to use, however....when I try to submit it uses the (Championship) submit, instead of its own (ClientCurr)

Here is the 2x submits
Response.Write("<select name=clientcurr class=inputbox onchange='javascript:this.form.submit();'>")
Response.Write("<option>"&ClientCurr&"</option>")
Response.Write("<option>---</option>")
Do Until SiteCurrency.EOF
Response.Write("<option>"&SiteCurrency("country_curr")&"</option>")
SiteCurrency.MoveNext
	Loop
SiteCurrency.Close
Response.Write("</select>")

Open in new window

Response.Write("<select name=championship class=inputbox onchange='javascript:this.form.submit();'>")
Response.Write("<option>Select Championship</option>")
Response.Write("<option>---</option>")
Do Until Championship.EOF
Response.Write("<option>"&Championship("code_name")&"</option>")
Championship.MoveNext
	Loop
Championship.Close
Response.Write("</select>")

Open in new window


Here is the If statement:
If Request.Form("championship")<>"" Then
ElseIf Request.Form("clientcurr")<>"" Then
End If

Open in new window


Any help is appreciated
0
Comment
Question by:Graeme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 41866928
add a hidden field, set that field with some sort of flag before submitting, then when processing your code, check that field to determine which drop down you're using:

Response.Write("<input type='hidden' name='mode' id='mode' value='' />")

Response.Write("<select name=clientcurr class=inputbox onchange='javascript: document.getElementById('mode').value = 'client'; this.form.submit();'>")
Response.Write("<option>"&ClientCurr&"</option>")
Response.Write("<option>---</option>")
Do Until SiteCurrency.EOF
Response.Write("<option>"&SiteCurrency("country_curr")&"</option>")
SiteCurrency.MoveNext
	Loop
SiteCurrency.Close
Response.Write("</select>")

Response.Write("<select name=championship class=inputbox onchange='javascript: document.getElementById('mode').value = 'championship'; this.form.submit();'>")
Response.Write("<option>Select Championship</option>")
Response.Write("<option>---</option>")
Do Until Championship.EOF
Response.Write("<option>"&Championship("code_name")&"</option>")
Championship.MoveNext
	Loop
Championship.Close
Response.Write("</select>")

Open in new window


then, when you submit, do:

dim mode : mode = Request.Form("mode")
if mode  = "championship" then

elseif mode = "client" then

end if

Open in new window

0
 

Author Comment

by:Graeme
ID: 41866947
Hi BigMonty and cheers for clarifying! :)

So I am guessing that this type of submit will just take whichever is first in line? for Request.Form's?

for dim mode : mode - where do i position this?
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 41866962
yes, if the client select box is changed, it'll submit with the "client" flag in the hidden variable (mode). same is true with the championship select box. you can add even more select boxes to include this functionality as well.

for your second question, this should clear it up:

<%
dim mode : mode = Request.Form("mode")
if mode  = "championship" then
	oConn.Execute("INSERT INTO site_log(log_session,brand_ID,log_page,log_date,log_time) VALUES("&Session_ID&",'"&SubDomain("brand_ID")&"','Show "&Request.Form("championship")&"','"&Date()&"','"&Time()&"')")
	Set Championship=oConn.Execute("SELECT * FROM codes WHERE code_name='"&Request.Form("championship")&"'")
	Response.Redirect("?code="&Championship("code_short"))
Else
' cut from code
%>
	<td width=330 height=40 nowrap align=middle>&nbsp;&nbsp;<select name=championship class=inputbox onchange='this.form.submit()'>
	<option>Select Championship</option>
	<option>---</option>
	<option>Championship("code_name")</option>
	</select><noscript><input type=submit value=Go! name=go class=inputsubmit></noscript></td>
<%
End If

if mode = "client" then

'-- do insert statement

else

build html for select
%>

Open in new window

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:Graeme
ID: 41866991
Cheers for that! :)

I think its making more sense now...

Have just applied the code changes, not much success thou - it is not attempting to submit any of the select boxes

	dim mode : mode = Request.Form("mode")
	If mode="championship" Then
		oConn.Execute("INSERT INTO site_log(log_session,brand_ID,log_page,log_date,log_time) VALUES("&Session_ID&",'"&SubDomain("brand_ID")&"','Show "&Request.Form("championship")&"','"&Date()&"','"&Time()&"')")
		Set Championship=oConn.Execute("SELECT * FROM codes WHERE code_name='"&Request.Form("championship")&"'")
		Response.Redirect("?code="&Championship("code_short"))
	ElseIf mode="clientcurr" Then
		Set oXMLHTTPClient=CreateObject("MSXML2.ServerXMLHTTP")
		ClientCurrAPI="http://apilayer.net/api/live?access_key=c1c108f1b397902542f2961ef3a98c30&currencies="&Request.Form("clientcurr")&"&source=USD&format=1"
		oXMLHTTPClient.Open "GET",ClientCurrAPI, False
		oXMLHTTPClient.Send
		If oXMLHTTPClient.Status=200 Then
			GetTextFromUrlClient=oXMLHTTPClient.responseText
			ArrClient1=Split(GetTextFromUrlClient,"USD"&SessionCurr("country_curr"))
			ArrClient2=Split(ArrClient1(1),":")
			ArrClient3=Split(ArrClient2(1)," ")
			ClientConvert=CDbl(ArrClient3(0))
		End If
		oConn.Execute("UPDATE site_sessions SET session_curr='"&SessionCurr("country_curr")&"',session_rate="&ClientConvert&",session_date='"&Date()&"',session_time='"&Time()&"' WHERE session_ID="&Session.SessionID)
		Response.Redirect("?")
	End If

Open in new window

		Response.Write("<input type='hidden' name='mode' id='mode' value='' />")
		Set Championship=oConn.Execute("SELECT * FROM codes WHERE code_live=TRUE ORDER BY code_name")
		Response.Write("<td width=1000 height=40 align=left valign=absmiddle>&nbsp;")
		Set ClientCountry=oConnAE.Execute("SELECT * FROM IATA_country WHERE IATA_2letter='"&ClientRegion&"'")
		Response.Write("<img height=30 width=30 valign=middle src=http://members.amnet.net.au/~webber4/flag-"&ClientRegion&".png> <b>"&ClientCountry("IATA_country")&"</b>")
		Set SiteCurrency=oConnAE.Execute("SELECT * FROM IATA_country WHERE curr_default=TRUE ORDER BY country_curr")
		Response.Write(" <select name=clientcurr class=inputbox onchange='javascript: document.getElementById('mode').value = 'client'; this.form.submit();'>")
		Response.Write("<option>"&ClientCurr&"</option>")
		Response.Write("<option>---</option>")
		Do Until SiteCurrency.EOF
		Response.Write("<option>"&SiteCurrency("country_curr")&"</option>")
		SiteCurrency.MoveNext
			Loop
		SiteCurrency.Close
		Response.Write("</select></td>")
		Response.Write("<td width=330 height=40 nowrap align=center><select name=championship class=inputbox onchange='javascript: document.getElementById('mode').value = 'championship'; this.form.submit();'>")
		Response.Write("<option>Select Championship</option>")
		Response.Write("<option>---</option>")
		Do Until Championship.EOF
		Response.Write("<option>"&Championship("code_name")&"</option>")
		Championship.MoveNext
			Loop
		Championship.Close
		Response.Write("</select></td>")

Open in new window

All the code is snipets from the page
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41866998
do you have a link to the page?
0
 

Author Comment

by:Graeme
ID: 41867003
I have PMd you the link and login details
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41867007
Why not just put each <select> in its own form.

That way when you do a this.form.submit() it submits the contents of the form that contains the <select> that triggered the submit.

You don't need them to be in the same form as each is doing an autosubmit and are therefore mutually exclusive.
HTML
		<form action="reflect.php" method="post">
			<select name="clientcurr" class="inputbox" onchange="javascript:this.form.submit();">
				<option>Option 1</option>
				<option>---</option>
				<option>GBP</option>
				<option>USD</option>
				<option>ZAR</option>
			</select>
		</form>
		<form action="reflect.php" method="post">
			<select name="championship " class="inputbox" onchange="javascript:this.form.submit();">
				<option>Option 1</option>
				<option>---</option>
				<option>ABC</option>
				<option>DEF</option>
				<option>GHI</option>
			</select>
		</form>

Open in new window

Working sample here
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 41867026
change

Response.Write(" <select name=clientcurr class=inputbox onchange='javascript: document.getElementById('mode').value = 'client'; this.form.submit();'>")
            
to

Response.Write(" <select name=clientcurr class=inputbox onchange='javascript: document.getElementById(""mode"").value = ""client""; this.form.submit();'>")
            
and change

Response.Write("<td width=330 height=40 nowrap align=center><select name=championship class=inputbox onchange=""javascript: document.getElementById('mode').value = 'championship'; this.form.submit();"">")
            
to

Response.Write("<td width=330 height=40 nowrap align=center><select name=championship class=inputbox onchange='javascript: document.getElementById(""mode"").value = ""championship""; this.form.submit();'>")
0
 

Author Comment

by:Graeme
ID: 41867051
the onchange for both is different (quotes within), is this to test which works?

Response.Write("<td width=330 height=40 nowrap align=center><select name=championship class=inputbox onchange=""javascript: document.getElementById('mode').value = 'championship'; this.form.submit();"">")

Open in new window

- this works for championship

tried clientcurr
Response.Write(" <select name=clientcurr class=inputbox onchange='javascript: document.getElementById(""mode"").value = ""client""; this.form.submit();'>")

Open in new window

changed clientcurr to below to match championship quotes above
Response.Write(" <select name=clientcurr class=inputbox onchange=""javascript: document.getElementById('mode').value = 'client'; this.form.submit();"">")

Open in new window


clientcurr, is submitting but i dont think to where it should, as it should be stopping at a Response.Write("updated")
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 41867063
you need to change the "mode" value to whatever client you're checking server side. it looks like you're checking for "clientcurr" so change the code to:

Response.Write(" <select name=clientcurr class=inputbox onchange=""javascript: document.getElementById('mode').value = 'clientcurr'; this.form.submit();"">")
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41867074
Separate forms?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41867093
not a big fan of multiple forms, as I don't find the scale well. if you need to add additional data fields to the page that are outside of the form elements, then it takes a lot more work to get it to work than simply adding a flag to the data that's posted and checking against that flag

just my .02 cents worth :)
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41867119
Except in this case that is exactly what he is doing - submitting mutually exclusive data.
Makes sense to use separate forms as it ring fences the contained control from any other control - no possibility of a mix up.
Scaling is going to be problematic any way you slice this thing as you are breaking the mold of how forms work (fields / submit button).

Personally I think it is the simplest solution.
0
 

Author Closing Comment

by:Graeme
ID: 41867215
Cheers BigMonty, working a treat! :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question