Auto Submit on dropdown box

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 :)
Graemewebber4technologiesAsked:
Who is Participating?
 
Kim WalkerConnect With a Mentor Web Programmer/TechnicianCommented:
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
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Graemewebber4technologiesAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Kim WalkerWeb Programmer/TechnicianCommented:
Can you post a link to the page? Do you have a form tag around the table?
0
 
Graemewebber4technologiesAuthor Commented:
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
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Kim WalkerWeb Programmer/TechnicianCommented:
What works? Does it submit the page when you select a different option? Or do you have to click the submit button?
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Graemewebber4technologiesAuthor Commented:
Yes the page refreshes, however it doesn't go to the page it supposed to..

I am using Chrome
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Julian HansenCommented:
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
 
Graemewebber4technologiesAuthor Commented:
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
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Graemewebber4technologiesAuthor Commented:
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
 
Graemewebber4technologiesAuthor Commented:
Hi Kim and cheers for clearing that up

What is the value that I am looking for?
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Graemewebber4technologiesAuthor Commented:
Ah ok, cheers
0
 
Julian HansenCommented:
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
All Courses

From novice to tech pro — start learning today.