I am using jquery’s thickbox. I have the basic following form which has some dropdowns. Each dropdown has a Info link besides it. I am trying to achieve is:
That when a user presses the info link it should open the showinfo.php?pid=selected value of that dropdown in the thickbox.
So in thickbox link it should be something like: showinfo.php?pid=123. But i don’t know how to get the value of dropdown and open the thickbox link i.e: showinfo.php at the same time ?
function updateSelectLink() {
var link = document.getElementById(this.id + 'link');
link.href = 'showinfo.php?' + this.value;
}
var form = document.getElementById('f1');
form.elements.dd1.onchange = updateSelectLink;
form.elements.dd2.onchange = updateSelectLink;
Thanks for the response. I was wondering How to go about the 2nd option ? I really don’t want to use a function for this and would prefer the 2nd option.
With the second option you would associate an onclick event of the link to a function
<a id="dd1_link" class="thickbox" ...>
var index = 1,
link;
while (true) {
link = document.getElementById('dd' + index + '_link');
if (!link) {
break;
}
link.onclick = updateLinkFromSelect;
index += 1;
}
so that the updateLinkFromSelect code can retrieve the appropriate select field and set the href value of the link.
function updateLinkFromSelect() {
var link = this,
select = document.getElementById(link.id.split('_')[0]);
link.href = 'showinfo.php?' + select.value;
}
Come on - stop kidding and get serious.
It might be possible to do it all without functions, but your future-self will find it very hard to understand what the function-free code does, and won’t be thanking you at all.
An alternative is to put each select in a separate individual form, so that when you submit the form, which can be easily triggered from a link, the form automatically sets the value after the question mark.