Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

dropdown menu without submit button


want to update page when user
uses dropdown menu


do not want submit button

can not change this line
<form id="xyz">







<form id="xyz">
<select>
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
</form>
ASKER CERTIFIED SOLUTION
Avatar of propakmike
propakmike
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
SOLUTION
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
SOLUTION
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
SOLUTION
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
Avatar of rgb192

ASKER


dont understand
 1st comment


2nd comment
document.getElementById('xyz').getElementsByTagName('select').onChange = "document.getElementById('xyz').submit()";
can i put this on the line before 'form'
because I cant change the <header></header> without editing many pages

3rd comment
my code submits to same page and do nto want to change this







4th comment
<select onChange="document.getElementsByTagName(\'form\')(0).submit()">onChange="document.getElementsByTagName(\'form\')(0).submit()">';

did not refresh page
Remove the backslashes around form?
<html>

<form id="xyz">
<select onchange="alert(this.options[this.selectedIndex].value);" >
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
</form>
</html>
Then if you want to pass it to the function:

<html>
 <script type="text/javascript">  
function selectfunction(mystring)
{
alert(mystring + ' was selected');
}


</script>
<form id="xyz">
<select onchange="selectfunction(this.options[this.selectedIndex].value);" >
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
</form>
</html>
Avatar of pattyn
pattyn

If you want to generate source using PHP you have to make a server request of some sort-- either a simple page either reloading the current or a new page or loading a page in an IFRAME.  Try looking at AJAX --here' is link:http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm
you need to add a onload event handler to make sure your element exists before trying to work with it, so this code should be able to be placed anywhere


<script type="text/javascript">
window.onload=function(){
document.getElementById('xyz').getElementsByTagName('select').onChange = "document.getElementById('xyz').submit()";
}
</script>

Open in new window

Avatar of rgb192

ASKER

<select onchange="alert(this.options[this.selectedIndex].value);" >


produced an alert text box


all of these did nothing
<script type="text/javascript">





is there a way to make the page refresh when dropdown select
This will:
<select onChange="document.getElementsByTagName('form')(0).submit()">

You just have to make sure you don't paste it twice again. And make sure it doesn't have backslashes in it.
Avatar of rgb192

ASKER

<select onChange="document.getElementsByTagName('form')(0).submit()">


this does not refresh the page

but your alert box worked
Yeah... I am stupid... square brackets:

<select onChange="document.getElementsByTagName('form')[0].submit()">
Avatar of rgb192

ASKER

<select onChange="document.getElementsByTagName('form')[0].submit()">



refreshes page
to
index.php?a=updatecart&ci[15044]=1


could i refresh page to
index.php


<select onChange="document.getElementsByTagName('form')[0].method="post";document.getElementsByTagName('form')[0].submit()">
Avatar of rgb192

ASKER

now page does not refresh
SOLUTION
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
Besides the fact that Ray's comment is absolutley correct, this might be a solution.

Put the script into the page.
<script type="text/javascript">
</--
function sendForm() {
    document.getElementsByTagName('form')[0].method="post";
    document.getElementsByTagName('form')[0].submit()
}
//-->
</script>

Then change the select to this line:

<select onChange="sendForm();">
Avatar of rgb192

ASKER

didnt refresh the page
Avatar of rgb192

ASKER

thanks