Page 1 of 1

[HOW TO] How to add ONCHANGE to forms

Posted: Mon Nov 29, 2010 7:11 am
by Gilmore
I found this simple JavaScript to change a form to when you select form the dropdown box. Once this is working, it shoudl allow you to select anything form the dropdown box on the Order page and it will automatically go to that page instead of clicking the Filter button.
I did try to add it, but I think I keep missing something! So below is the example I found. I was trying to add it to the admin/view/template/saleorder_list.tpl on the form found around line 17.
Maybe one of our finder minds on here can whip this!

Code: Select all

<Script language="JavaScript">
<!-- 
function goto(form) { var index=form.select.selectedIndex
if (form.select.options[index].value != "0") {
location=form.select.options[index].value;}}
//-->
</SCRIPT>
<FORM NAME="form1">
<SELECT NAME="select" ONCHANGE="goto(this.form)" SIZE="1">
<OPTION VALUE="">-------Choose a Selection-------
<OPTION VALUE="index.htm">Home
<OPTION VALUE="web_development.htm">Web Development
<OPTION VALUE="html_codes.htm">HTML Tips
<OPTION VALUE="html_codes_chart.htm">HTML Code Chart
<OPTION VALUE="javascript_codes.htm">JavaScript Codes
<OPTION VALUE="216_color_chart.htm">Color Code Chart</SELECT>
</FORM>
Here's what I did so far. I added this before the <form tag on line 17.

Code: Select all

<!-- Start Form MOD ONCHANGE -->
<Script language="JavaScript">
<!--
function goto(form) {
 var index=form.select.selectedIndex
if (form.select.options[index].value != "0") {
location=form.select.options[index].value;}}
//-->
</SCRIPT>
<!-- End Form MOD ONCHANGE -->
Then I added name="form1" to

Code: Select all

<form action="" method="post" enctype="multipart/form-data" id="form">
making it

Code: Select all

<form action="" method="post" enctype="multipart/form-data" id="form" name="form1">
And finally I added ONCHANGE="goto(this.form)" to

Code: Select all

<select name="filter_order_status_id">
so it reads as

Code: Select all

<select name="filter_order_status_id" ONCHANGE="goto(this.form)">
Since the example shows that the <select name="" should be "select", I used the existing name, name="filter_order_status" that was already there and changed every instance of it in the SCRIPT above. I replaced form.select. with form.filter_order_status. All that did was read the number selected for that particular selection. I take it since it is already being used by more of the select function below where you find it, that it has something to do with only displaying the number of that selection. I'm sure it's something simple I am missing! lol SO that is where I am stuck! haha...anyone have a tow rope?

Thanks,
Gilmore

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Mon Nov 29, 2010 7:46 am
by justinv
Hi Gilmore, I just replied to your PM.

And so I stay on topic and don't railroad your post, try this for your problem:

Code: Select all

ONCHANGE="document.location = this.options[this.selectedIndex].value;"
All you need to change is part of this line:

Code: Select all

<select name="filter_order_status_id" ONCHANGE="goto(this.form)">

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Mon Nov 29, 2010 8:48 am
by Gilmore
I'm not following you on this one Justin. Can you show it ad the actual edits it needs?

Thanks,

Gilmore

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Mon Nov 29, 2010 9:07 am
by justinv
You have this:

Code: Select all

<select name="filter_order_status_id" ONCHANGE="goto(this.form)">
Replace it with this:

Code: Select all

<select name="filter_order_status_id" ONCHANGE="document.location = this.options[this.selectedIndex].value;">

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Mon Nov 29, 2010 9:26 am
by Gilmore
Nope that doesn't do it. Still gets the same error. Page not found and the URL is... .com/admin/0
Can't it stay as it is and then use id="filter_order_status_id" instead of name="filter_order_status_id" on the select so then the name="" can be name="select"
that is the only thing I see that I can't seem to set right in this.
or...can the php and javascript below this use the id= instead of name=? It seems the only place that is calling for filter_order_status_id is the php code below it so it will select the correct OPTION VALUE.

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Tue Nov 30, 2010 12:19 pm
by Gilmore
Well I tried it a couple of different ways and it is still a no go. Now it really has me stumped! lol

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Tue Nov 30, 2010 1:36 pm
by justinv
Mind sending a link to the site?

Re: [HOW TO] How to add ONCHANGE to forms

Posted: Wed Dec 01, 2010 3:00 am
by Gilmore
It's not on a site yet. I do all my testing on my local box before it goes hot. Just follow what I have above and you will be able to reproduce it.