Solved

Auto Submit on dropdown box

Posted on 2016-10-31
14
27 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
  • 6
  • 5
  • 3
14 Comments
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
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 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
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
 

Author Comment

by:Graeme
Comment Utility
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 32

Expert Comment

by:Big Monty
Comment Utility
do you have a link to the page?
0
 

Author Comment

by:Graeme
Comment Utility
I have PMd you the link and login details
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
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 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
Separate forms?
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
Cheers BigMonty, working a treat! :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now