Reputation: 27899
I need to pass a URL to a JavaScript function something like the following.
<script type="text/javascript" language="javascript">
var xmlhttp='';
function ajax()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp = new ActivexObject("Microsoft.XMLHTTP");
}
}
function someFunction(orders_per_page, url)
{
ajax();
var val=document.getElementById("txt_order_amount").value;
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("list").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",url, true);
xmlhttp.send();
}
</script>
<select
id="cmb_page" name="cmb_page"
onchange="someFunction(this.value, "reports/OrderAmount.php?val="+val+"&orders_per_page="+orders_per_page+"&pageNo="+getSelectedPage();">
<option value="1">Some Value</option>
</select>
I need to pass a URL string as mentioned on the onchange
even of the <select><option></option></select>
element. Is it possible?
Upvotes: 0
Views: 971
Reputation: 70139
You can also break your code a little bit to prevent as much tag soup.
I assume your val
var is defined and in the global scope:
onchange="someFunction(this.value)"
function someFunction(orders_per_page) {
var url = "reports/OrderAmount.php?val="+val+"&orders_per_page="+orders_per_page+"&pageNo="+getSelectedPage();
ajax(); // ... rest of your function
Make sure getSelectedPage()
is returning a string
, or a number which can be parsed as string.
Upvotes: 1
Reputation: 26376
try this
onchange="someFunction(this.value, 'reports/OrderAmount.php?val='+val+'&orders_per_page='+orders_per_page+'&pageNo='+getSelectedPage());"
Note: I have replaced double quotes with single quotes
Upvotes: 1