Link to home
Start Free TrialLog in
Avatar of Graeme McGilvray
Graeme McGilvrayFlag for Australia

asked on

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 :)
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

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?
Avatar of Graeme McGilvray

ASKER

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
Can you post a link to the page? Do you have a form tag around the table?
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
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?
What works? Does it submit the page when you select a different option? Or do you have to click the submit button?
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.
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

Yes the page refreshes, however it doesn't go to the page it supposed to..

I am using Chrome
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.
Avatar of Julian Hansen
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
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
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.
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

ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Kim and cheers for clearing that up

What is the value that I am looking for?
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.
Ah ok, cheers
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.