Forum Moderators: coopster

Message Too Old, No Replies

call javascript function

         

kristof_v

9:26 am on Dec 1, 2006 (gmt 0)

10+ Year Member



hi guys,

in this piece of code i would like to call a javascript function from php:

if (isset($_GET['ord']) && isset($_GET['type'])) {
//check if a reload of the select boxes is necessary
echo '<script language="javascript">orderReportsReload()</script>';

but the function doesn't get called :(

[edited by: kristof_v at 9:40 am (utc) on Dec. 1, 2006]

kristof_v

9:27 am on Dec 1, 2006 (gmt 0)

10+ Year Member



when the function is called only the alert is ebing executed.
very strange.

this is the functiuon:

function orderReportsReload() {
alert("test");

var ordername = document.listReportsForm.selectOrderName.options[document.listReportsForm.selectOrderName.selectedIndex].value;
var ordertype = document.listReportsForm.selectOrderType.options[document.listReportsForm.selectOrderType.selectedIndex].value;

window.location = "index.php?page=reports/list_all&ord=" + ordername + "&type=" + ordertype;
}

in another functio i already use
var ordername = document.listReportsForm.selectOrderName.options[document.listReportsForm.selectOrderName.selectedIndex].value;
var ordertype = document.listReportsForm.selectOrderType.options[document.listReportsForm.selectOrderType.selectedIndex].value;

window.location = "index.php?page=reports/list_all&ord=" + ordername + "&type=" + ordertype;

and there it works great so i don't get it

kristof_v

10:42 am on Dec 1, 2006 (gmt 0)

10+ Year Member



i think that i'm calling the function to soon, when the select boxes have not changed yet.
that's why it doesn't seem like it's working but it actually does

eelixduppy

12:03 pm on Dec 1, 2006 (gmt 0)



I'm thinking that a total JavaScript solution would be best for this, but would you settle for just a regular form?


<form method="get" action="index.php">
<select name="ord">
...blah blah blah...
</select>
<select name="type">
...blah blah blah...
</select>
<input type="hidden" name="page" value="reports/list_all" />
<input type="submit" />
</form>

Not sure if this fits into your page or not, but it seems like a reasonable solution instead of making it more difficult for yourself with JavaScript. ;)

Good luck!