1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Using javascript to send values via php GET

Discussion in 'Web Design & Development' started by twmprys, Apr 30, 2010.

Thread Status:
Not open for further replies.
  1. twmprys

    twmprys Thread Starter

    Joined:
    Jun 4, 2009
    Messages:
    111
    Hope someone can help. I've got a php script printing out all the ROWS from a MYSQL database, and after each row a dropdown menu. What I'm trying to achieve is this: on selecting an OPTION VALUE from any one menu (ONCHANGE), a javascript function is immediately activated to pass both that OPTION VALUE and the id of the MYSQL ROW into the browser (ready for PHP GET).

    I can pass the MYSQL ROW id into the browser no problem - how can I add the OPTION VALUE into the browser as well?

    HTML:
    <script type="text/javascript">
    function typeAlert(uid) {
    var OK = confirm("OK to update type?")
    if(OK){
    window.location = 'updatepage.php?id='+uid;
    }
    }
    </script>
    <select id="dropdown1" onchange="return typeAlert('<?php echo row['id']; ?>');">
    <option value="1" selected="selected">Type 1</option>
    <option value="2">Type 2</option>
    <option value="3">Type 3</option>
    </select>
     
  2. andythepandy

    andythepandy

    Joined:
    Jul 2, 2006
    Messages:
    379
    All you need to do is add a value argument to your typeAlert function
    Code:
    function typeAlert(uid, value) {
       var OK = confirm("OK to update type?")
       if(OK){
          window.location = 'updatepage.php?id='+uid+'&value='+value;
       }
    }
    
    and then when you call it feed this.value into it like
    Code:
    <select id="dropdown1" onchange="return typeAlert('<?php echo row['id']; ?>', this.value);">
    <option value="1" selected="selected">Type 1</option>
    <option value="2">Type 2</option>
    <option value="3">Type 3</option>
    
    Hope that helps,
    Andy
     
  3. twmprys

    twmprys Thread Starter

    Joined:
    Jun 4, 2009
    Messages:
    111
    That's brilliant - thanks!
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/920245

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice