[SOLVED] passing parameters with javascript functions
Posted: Sat Apr 16, 2005 2:23 am
Hi.
I am trying to modify a JavaScript code for livesearch functions, (also known as AJAX etc...) which uses XMLHttpRequest. It's all working fine with one search form on the page, but I'm trying to have multiple forms using this on the same page. So, I thought, I should simply pass the name of the form as a parameter, which will then be passed on to the php scripts which will know what to do with it.
Since I am not very experienced with JavaScript, I'm doing something wrong. Originally, this was used for one input box whose name = "q":
Which I then changed to:
Now, I am still passing the value of q as parameter from the web page, i.e. onkeypress = liveSearchDoSearch(q), but the code doesn't work the same anymore. Any idea why?
Furthermore (once the above gets fixed), I will need to change the portion:
to replace "q" with whatever parameter was passed. I can already see, however, that simply doing
doesn't do the trick.
These are some very basic questions -- I am new to JavaScript, and I'd be very grateful for some hints.
All best,
Tench
I am trying to modify a JavaScript code for livesearch functions, (also known as AJAX etc...) which uses XMLHttpRequest. It's all working fine with one search form on the page, but I'm trying to have multiple forms using this on the same page. So, I thought, I should simply pass the name of the form as a parameter, which will then be passed on to the php scripts which will know what to do with it.
Since I am not very experienced with JavaScript, I'm doing something wrong. Originally, this was used for one input box whose name = "q":
Code: Select all
function liveSearchDoSearch() {
liveSearchReq.open("e;GET"e;, liveSearchRoot + "e;/lsearch?q="e; + document.forms.searchform.q.value + liveSearchParams);
}Code: Select all
function liveSearchDoSearch(which){
liveSearchReq.open("e;GET"e;, liveSearchRoot + "e;/lsearch?"e; + which + "e;="e; + document.forms.searchform.q.value + liveSearchParams);
}Furthermore (once the above gets fixed), I will need to change the portion:
Code: Select all
document.forms.searchform.q.valueCode: Select all
document.forms.searchform.which.valueThese are some very basic questions -- I am new to JavaScript, and I'd be very grateful for some hints.
All best,
Tench