Hi, I’m working on an open source project for some non-profit organisations. I’m want to change this line:
<select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $_SERVER'PHP_SELF'] ?>?option=XXXXXXX&page=XXXXXXX&product_id='+document.getElementById('product_id').options[selectedIndex].value; ">
to a line that does not only take the &product_id value, read from a dropdown selection menu, but also the &order_id="$order_id"&user_id="$user_id"
I’ve tried many options, but somehow I’m not using the right quotes at the right moment.
Hope this is enough to see what I mean.
Try:
<select class=“inputbox” id=“product_id” name=“product_id” onchange="window.location=‘<?php echo $_SERVER’PHP_SELF’] ?>?option=XXXXXXX&page=XXXXXXX&order_id=<?php echo $order_id; ?>&user_id=<?php echo $user_id; ?>&product_id='+document.getElementById(‘product_id’).options[selectedIndex].value; ">
Have you thought of using some kind of javascript framework like jQuery (my fave)?
Left it too long to edit
This is neater (using a function):
<select class=“inputbox” id=“product_id” name=“product_id”
onchange=“buildUrl(document.getElementById(‘product_id’).options[selectedIndex].value);”>
<option value=“1”>1</option>
<option value=“2”>2</option>
<option value=“4”>4</option>
</select>
<script type=“text/javascript”>
function buildUrl(prodid) {
url=“foo.html?option=XXXXXXX&page=XXXXXXX”;
url+=“&product_id=”+prodid;
url+=“&user_id=foo&order_id=bar”;
window.location=url;
}
</script>
Obviously, I called my page foo.html, not having a php environment on me…
Thank you so very much…I’m not at my machine now, but will try tonight and post results. Same for second solution, which is more elegant IMHO.
Thanks again,
Gertjan
The first one:
<select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $_SERVER'PHP_SELF'] ?>?option=XXXXXXX&page=XXXXXXX&order_id=<?php echo $order_id; ?>&user_id=<?php echo $user_id; ?>&product_id='+document.getElementById('product_i d').options[selectedIndex].value; ">
does not work. It does not complain, the values are not used. Changed via ssh and vi, will change other solution tonight.
Thanks anyway
Cheers again !!! Got it solved. Both didn’t work, there’s definitely something wrong in the single or double quotes. This does the job:
<?php
$url = $_SERVER'PHP_SELF']."?option=XXXXXXX&page=XXXXXXX&order_id=". $order_id . "&user_id=" . $user_id ;
?>
<select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $url ?>&product_id='+document.getElementById('product_id').options[selectedIndex].value; ">
I can’t realy see the difference, but it’s working now !!! I recognized the second way to work it out, and remembered I had about the same problem in the beginning of this project, late last year. Quite elegant as well IMHO.
Glad you got it fixed
I think the quotes problem might be because I didn’t check actually echo’ing out the values - missed a trick there…
I like the web developer toolbar for firefox. It’s got a nice javascript debugger in it which helps with things like that. Worth getting that & firebug if you’re doing much web work.
Thanks. I’ll have a look at those. And
if you do much webwork
: this is what I’m working on, I consider it as quite a lot:
This one counts the lines for all modules on my project:
find /srv/www/htdocs -iname ‘. _. ’ | xargs -n 1 wc -l | cut -d’ ’ -f1 | (SUM=0; while read NUM; do SUM=$(($SUM+$NUM)); done; echo $SUM)
It outputs: 843658
Considering the trouble the post was about: I forgot a very important guideline some php programmer gave me before I started the project: “In case of confusion caused by mixture of php-, html- and javascript statements and their use of quotes, pack them all into to single php-statements and glue those together”. In the end, that’s what I did.
Man alive.
That’s a lot of code I do smallish websites for fun and occasionally profit.
I will bow down to your greater linecount though
dmera
November 6, 2009, 3:04am
10
Hi Knurpht,
I liked your counting command and I wanted to improve it a bit as I didn’t like the loop and there is one less filtering now. I think it will be a bit faster(only you can verify that)
find /srv/www/htdocs -iname ‘. _. ’ | xargs -n 1 wc -l | awk ‘{SUM=SUM+$1} END {print SUM}’