Forum Moderators: open
I have a form, with two select menus and also an input area,
Both drop downs on change send the new url to the browser for a page reload onChange, these work fine on both drop downs.
I wanted to get the text from the input box (onchange) into the url of both drop down menus.
Code for the drop down onChange is as follows (using php here aswell):
onChange="if(options[selectedIndex].value) window.location.href=\'index.php?apid='.$_GET['apid'].'&psid='.$_GET['psid'].'&pg='.$_GET['pg'].'&colsort='.$_GET['colsort'].'&sortby='.$_GET['sortby'].'&gf=\'+(options[selectedIndex].value)+\'&ss='.$_GET['ss'].'\'"
I need to get the user input in the text input area into the var value ss at the end of the js url.
Im under the impression this will be a small function to inject the value of the text area onChange into the defined area of the js url for both select menus.
Any help here would be great
TIA
<select id="s1" name="s1" onchange="go(this)">
<option value="s1value1">s1 value1</option>
<option value="s1value2">s1 value2</option>
</select>
<input type="text" name="t" id="t">
And in JS:
function go(s) {
var tvalue = document.getElementById("t").value;
if (tvalue == "") tvalue = '<?php echo $_GET['ss']?>';
window.location.href = "page.php?gf="+s.options[this.selectedIndex].value+"&ss="+tvalue;
}
I would suggest storing $_GET['ss'] in another variable, and making sure there are no quotes in it before trying to insert it into javascript.
Does this help?
- JS
I have two select menus similar to:
<select name="select1" onChange="if(options[selectedIndex].value) window.location.href='index.php?select1='+(options[selectedIndex].value)+'&searchString='+GET VALUE FROM JAVASCRIPT+''">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
<option value="4"></option>
</select>
<select name="select2" onChange="if(options[selectedIndex].value) window.location.href='index.php?select2='+(options[selectedIndex].value)+'&searchString='+GET VALUE FROM JAVASCRIPT+''">
<option value="a"></option>
<option value="b"></option>
<option value="c"></option>
<option value="d"></option>
</select>
And also a text input:
<input type="text" name="searchString" value="" size="20" />
What i would like to do here is, when the value of the text input box is changed (without submitting the form), have its value inserted into the end of the onChange URLS (&searchString='+GET VALUE FROM JAVASCRIPT+') in the two select menus so when the menus are used after text has been inserted into the box, the menus will use that text input as part of the filters being passed to the script.
I am assuming that i would need a small function to determine if the content has changed in the text input box and for it to then insert its value into the searchString parameter of the url in the select menu's onChange event handler (if thats what it should be refered to as lol)
TIA
If a user types something into the textbox, nothing will happen.
But if the user types something into the text box, then selects either of the select boxes, it will run the "go" function, which sends the current select box.
It checks the text box for text and defaults to the current php value if the current text box is empty (you could also just set the text box value to the php variable)
It then sets the url to contain both the selectedIndex value and the textbox text.
- JS