Solved

Auto Submit on dropdown box

Posted on 2016-10-28
19
34 Views
Last Modified: 2016-10-31
Hi there, I am trying to create an auto submit for a dropdown box, however running into some issues...

The issue, is its not going to the submit page..

<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>

Open in new window


If I remove the <noscript> and onchange, then it works

Any help is appreciated :)
0
Comment
Question by:Graeme
  • 10
  • 7
  • 2
19 Comments
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864891
The purpose of the noscript tag is to show a message in the rare situations when javascript has been disabled or is not functional in a given browser. So the submit button that is contained inside the <noscript> tags will only rarely be visible.

The onchange would probably work with correct code. The this object referenced in the onchange attribute should be the form. So it isn't necessary to include form in your dot notations.
onchange="this.submit();"

Open in new window


What doctype are you using for your page? The code resembles HTML 4.01 or earlier version code. There are attributes that aren't supported in HTML5. Specifically the width, height, nowrap, and align attributes of the <td> tag.

I must assume there is a form element outside the table which contains this td cell. If not, there would be nothing to submit in javascript.

With this said, it is probably not a good idea to automatically submit a form when an option is selected from a select list. What if the user accidentally selects the wrong option and doesn't realize it?
0
 

Author Comment

by:Graeme
ID: 41864894
Hi there, have updated to onchange="this.submit();" as suggested, it doesnt do anything now, no submission attempt

I am using ASP Classic

This option is on every page at the top, so if they choose the wrong one, its no biggie
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864900
Can you post a link to the page? Do you have a form tag around the table?
0
 

Author Comment

by:Graeme
ID: 41864902
yes the form is there, as mentioned before it works when I dont add in the javascript

ill PM the link as it not live
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864903
My mistake. It appears the form is required.
onchange="this.form.submit();"

Open in new window

What happens when you select a different option? Can you post the form element so we can see what is supposed to happen?

Also, you didn't answer what doctype you are using?

Or better yet, can you post a link to the page?
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864904
What works? Does it submit the page when you select a different option? Or do you have to click the submit button?
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864907
OK. I received your message and visited the page. It works fine for me. The page refreshes when I change the selection as it should. What browser are you using?

I was also able to determine that you are not specifying a doctype. So the browser should be defaulting to HTML 4.01 Transitional. But you do have at least one HTML5 placeholder attribute.

I also see that the absence of quotes around your attribute values is causing several errors, especially for the query string values in your <a> elements. When an attribute value contains anything other than letters, numbers, periods, or underscores, it must be quoted. The question marks in the query strings are causing errors. The href should also begin with a forward slash to be a valid URL. For example, the href for the Tickets link should be
<a class=menu href="/?tickets=all">Tickets</a>

Open in new window

It is a good idea to put quotes around ALL your attribute values. But I believe this is beside the point of this question.
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864908
Since this is defaulting to the HTML 4.01 Transitional doctype, it is a good idea to include the script type in the onchange attribute value.
onchange="javascript: this.form.submit();"

Open in new window

0
 

Author Comment

by:Graeme
ID: 41864909
Yes the page refreshes, however it doesn't go to the page it supposed to..

I am using Chrome
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 21

Expert Comment

by:Kim Walker
ID: 41864912
Do you have ASP code to parse the submitted form and redirect the page based on the selection from the drop down list? The only thing the onchange code does is submit the form. It doesn't navigate to a different page unless the form contains a different page URL in the action attribute. Your form's action attribute is empty.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41865198
Just put a sample together using your code appears to work

Without seeing this in context though difficult to make a call - can we see a link
0
 

Author Comment

by:Graeme
ID: 41865602
Hi Kim, I have reverted back to the button so you can see that it is working, it submits to itself. however just uses and Request.Form to output.

Julian - thanks for that, however the setup seems to be ok, its that the page isnt going to the submit Request.Form
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41865605
Either way, with the button or with the onchange, the form is set up to submit to itself. It is doing that properly. Are you saying that you get redirected to a different page when you use the button? What is Request.Form? .Form is not a proper file extension. Where is it located?

If you are being redirected to a different page with the button, that means there is a code somewhere that is checking for the presence of the submit button. This would be in the ASP code of the page, not the HTML or javascript.
0
 

Author Comment

by:Graeme
ID: 41865606
Request.Form is from the IF statement.

If Request.Form("go")="Go!" 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"))
End If

Open in new window

0
 
LVL 21

Accepted Solution

by:
Kim Walker earned 500 total points
ID: 41865613
This explains it all. I'm not an ASP expert so I was unfamiliar with the term Request.Form. I see now that Request.Form is the submitted form. The first line of the code you've posted is testing for the presence of the submit button. Request.Form("go") will only equal "Go!" when the submit button is clicked. It will likely not be present in Request.Form at all if the form is submitted by selecting an option from the select list.

So there's nothing wrong with the javascript or HTML. You need to alter the ASP code to detect when the select list value has changed and redirect accordingly. You should probably create a new question and be sure to include ASP in the subject tags.
1
 

Author Comment

by:Graeme
ID: 41866431
Hi Kim and cheers for clearing that up

What is the value that I am looking for?
0
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41866433
I'm afraid I don't know much about ASP. You'll need to post a new question and tag ASP so the ASP experts can help you.
0
 

Author Comment

by:Graeme
ID: 41866435
Ah ok, cheers
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41866637
The name of your select box is "championship" so you could look for that but now we are getting into design problems.

If you have a form that can be submitted with a submit button or a select change you have two different triggers - so now your code needs to be aware of them.

A better option might be for your onchange is rather to trigger a click on the submit - that way you always come in to your ASP code with a click on the submit button and you can then do you check for form post there.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

757 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

15 Experts available now in Live!

Get 1:1 Help Now