Results 1 to 10 of 10

Thread: Need help with html / php / javascript

  1. #1
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Need help with html / php / javascript

    Hi, I'm working on an open source project for some non-profit organisations. I'm want to change this line:

    Code:
    <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.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  2. #2
    Join Date
    Sep 2008
    Location
    Earl Shilton UK
    Posts
    298

    Default Re: Need help with html / php / javascript

    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)?
    Happily using Linux since 1998
    Share & Enjoy

  3. #3
    Join Date
    Sep 2008
    Location
    Earl Shilton UK
    Posts
    298

    Default Re: Need help with html / php / javascript

    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...
    Happily using Linux since 1998
    Share & Enjoy

  4. #4
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Re: Need help with html / php / javascript

    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
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  5. #5
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Re: Need help with html / php / javascript

    The first one:

    Code:
    <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
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  6. #6
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Re: Need help with html / php / javascript

    Cheers again !!! Got it solved. Both didn't work, there's definitely something wrong in the single or double quotes. This does the job:
    Code:
    	      <?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.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  7. #7
    Join Date
    Sep 2008
    Location
    Earl Shilton UK
    Posts
    298

    Default Re: Need help with html / php / javascript

    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.
    Happily using Linux since 1998
    Share & Enjoy

  8. #8
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Re: Need help with html / php / javascript

    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.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  9. #9
    Join Date
    Sep 2008
    Location
    Earl Shilton UK
    Posts
    298

    Default Re: Need help with html / php / javascript

    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
    Happily using Linux since 1998
    Share & Enjoy

  10. #10
    Join Date
    Sep 2008
    Location
    Toronto,Canada
    Posts
    549

    Default Re: Need help with html / php / javascript

    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}'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •