0

I am trying to make a function like this but i need the parameters to be a string .

function viewrestaurant(int)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("boxcenter").innerHTML=xmlhttp.responseText;
    }
  }

	
xmlhttp.open("GET","viewrestaurant.php?viewr="+int,true);

xmlhttp.send();
}

this works find when i use the function i can run it fine but only as an int as seen here

function viewrestaurant(int)

How could i replace int with a string? it doesnt work, nor a var. thanks all for your help.

3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by fobos
0

Javascript function parameters are untyped. 'int' in your case is the name of the variable, not the integer type.

0

pritaeas is right. But if you want to change it from 'int' to something else, you have to change it in the AJAX function

function viewrestaurant(int){if (window.XMLHttpRequest)

and here to reflect:

viewrestaurant.php?viewr="+int
0

Im not doing the work for you. I only helped you out on what you needed.

I am trying to make a function like this but i need the parameters to be a string

just apply it to your code

0

I just need a string where it says int, but only an integer works.
When i try to do like this,

viewrestaurant("name")

int doesn't become "name" only a number will work there, so i was wondering why the function params wont accept a string. thanks

0

dont use quotes in your function. do you even understand this or did you just copy the code and now you want people to solve it for you?

name is a variable. so if you have a function like

<a href="javascript:viewrestaurants(2)">view</a>

the 2 would be passed to the function viewrestaurants(int) because the function requires a variable which in this case is int or name or whatever you want it to be.

0

try this

<script type="text/javscript">
function show(var1, var2) {
    alert("I can count: " +var1+" "+var2);
}
</script>
<a onclick="show('Hey','Whats up')">click</a> 
or 
<a onclick="show('1','2')">click</a>

Edited by fobos: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.