calling variable in onchange function

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default calling variable in onchange function

    I am using a javafunction (onclick in select) in which i am calling a
    function in php (thats why i send this to both php and javascript
    newsgroups).

    in the onclick i call the function "Place_Selected" with the value from the
    select (naam_keuze.value)

    in the function the value becomes the $zoek_id and searches in the database
    for the record with the id of $zoek_id

    the naam_keuze.value does not give the value to $zoek_id

    When i replace naam_keuze.value for a number (15) i works great.

    WHAT AM I DOING WRONG?


    This is my code



    Function Place_Selected($zoek_id)
    {
    include("data.php");
    $link=mysql_connect($db_host, $username, $password) or die("Database
    error!");
    mysql_select_db($database , $link)or die("Couldn't open $db:
    ".mysql_error());
    $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

    if ($sql)
    {
    while($blah2 = mysql_fetch_array($sql))
    {
    $newsid = $blah2['id'];
    $sticky = $blah2['naam'];
    }
    }
    return("document.form.achternaam.value='$sticky'") ;
    }


    <select id=naam_keuze size=1 name=keuze style=visibility:hidden
    onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
    =naam_keuze.value;>
    <option value=0>Kies
    $options
    </select>

    Thanks for suggestions

    roy


    R.G. Vervoort Guest

  2. Similar Questions and Discussions

    1. Setting a CF variable onChange in <select>
      Hi, How can I compare and a variable when a specific selection is made from a <select> list. ie. The select list looks like this... <select...
    2. Calling a function within a function registered to an event
      Hey, Just registered and tried to search through the forum for a solution to my problem, but I haven't found anything that could help me. I've...
    3. Calling a function using a variable
      I'm positive I've done this before, but I can't seem to figure it out again or find the FLA I did it in. I need to set a variable with the name of...
    4. Refreshing a href variable using OnChange of a select list
      Hi all, I'm trying to use the following script: <script language="javaScript"> function setrepto(){ document.aForm.repno.value =...
    5. calling clientside js with onchange event
      Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some...
  3. #2

    Default Re: calling variable in onchange function

    R.G. Vervoort wrote:
    > I am using a javafunction (onclick in select) in which i am calling a
    > function in php (thats why i send this to both php and javascript
    > newsgroups).
    >
    > in the onclick i call the function "Place_Selected" with the value from the
    > select (naam_keuze.value)
    >
    > in the function the value becomes the $zoek_id and searches in the database
    > for the record with the id of $zoek_id
    >
    > the naam_keuze.value does not give the value to $zoek_id
    >
    > When i replace naam_keuze.value for a number (15) i works great.
    >
    > WHAT AM I DOING WRONG?
    >
    >
    > This is my code
    >
    >
    >
    > Function Place_Selected($zoek_id)
    > {
    > include("data.php");
    > $link=mysql_connect($db_host, $username, $password) or die("Database
    > error!");
    > mysql_select_db($database , $link)or die("Couldn't open $db:
    > ".mysql_error());
    > $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");
    >
    > if ($sql)
    > {
    > while($blah2 = mysql_fetch_array($sql))
    > {
    > $newsid = $blah2['id'];
    > $sticky = $blah2['naam'];
    > }
    > }
    > return("document.form.achternaam.value='$sticky'") ;
    > }
    >
    >
    > <select id=naam_keuze size=1 name=keuze style=visibility:hidden
    > onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
    > =naam_keuze.value;>
    > <option value=0>Kies
    > $options
    > </select>
    >
    > Thanks for suggestions
    >
    > roy
    >
    >
    I don't see how it could work, even with a numeric value of 15... What
    version of PHP are you using?

    Here's why I think it shouldn't work...

    Javascript is client side - PHP is server side... thus, you attempt to
    call Place_Selected (PHP code) in your onChange event - This won't
    happen unless you hava a javascript function with that name that submits
    the form contents to the server via a FORM POST or GET...

    Also... The value for your select box should I believe end up in
    $_POST['keuze'] in PHP when the form is submitted...

    And... return("document.form.achternaam.value='$sticky'") ;
    Again, you've got your knickers in a twist - the return statement will
    not return a value into achternaam like I think you expect... I really
    think you are misunderstanding how the two technologies fit together...

    If you are sure that your test will work when you enter 15 as a test
    value - try different numbers to confirm that test works - If it does,
    then I think you've not provided the entire code here for me (perhaps
    anyone else) to give a full and proper answer/suggestion.

    Does any of the above help?
    randelld
    Reply Via Newsgroup Guest

  4. #3

    Default Re: calling variable in onchange function

    it works great, as long as the number (15 or ...) is an id in the database.
    i just will not accept the "." (dot) in the line



    "Reply Via Newsgroup" <reply-to-newsgroup@please.com> schreef in bericht
    news:J9kfc.121495$Ig.78826@pd7tw2no...
    > R.G. Vervoort wrote:
    >
    > > I am using a javafunction (onclick in select) in which i am calling a
    > > function in php (thats why i send this to both php and javascript
    > > newsgroups).
    > >
    > > in the onclick i call the function "Place_Selected" with the value from
    the
    > > select (naam_keuze.value)
    > >
    > > in the function the value becomes the $zoek_id and searches in the
    database
    > > for the record with the id of $zoek_id
    > >
    > > the naam_keuze.value does not give the value to $zoek_id
    > >
    > > When i replace naam_keuze.value for a number (15) i works great.
    > >
    > > WHAT AM I DOING WRONG?
    > >
    > >
    > > This is my code
    > >
    > >
    > >
    > > Function Place_Selected($zoek_id)
    > > {
    > > include("data.php");
    > > $link=mysql_connect($db_host, $username, $password) or die("Database
    > > error!");
    > > mysql_select_db($database , $link)or die("Couldn't open $db:
    > > ".mysql_error());
    > > $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");
    > >
    > > if ($sql)
    > > {
    > > while($blah2 = mysql_fetch_array($sql))
    > > {
    > > $newsid = $blah2['id'];
    > > $sticky = $blah2['naam'];
    > > }
    > > }
    > > return("document.form.achternaam.value='$sticky'") ;
    > > }
    > >
    > >
    > > <select id=naam_keuze size=1 name=keuze style=visibility:hidden
    > >
    onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
    > > =naam_keuze.value;>
    > > <option value=0>Kies
    > > $options
    > > </select>
    > >
    > > Thanks for suggestions
    > >
    > > roy
    > >
    > >
    >
    > I don't see how it could work, even with a numeric value of 15... What
    > version of PHP are you using?
    >
    > Here's why I think it shouldn't work...
    >
    > Javascript is client side - PHP is server side... thus, you attempt to
    > call Place_Selected (PHP code) in your onChange event - This won't
    > happen unless you hava a javascript function with that name that submits
    > the form contents to the server via a FORM POST or GET...
    >
    > Also... The value for your select box should I believe end up in
    > $_POST['keuze'] in PHP when the form is submitted...
    >
    > And... return("document.form.achternaam.value='$sticky'") ;
    > Again, you've got your knickers in a twist - the return statement will
    > not return a value into achternaam like I think you expect... I really
    > think you are misunderstanding how the two technologies fit together...
    >
    > If you are sure that your test will work when you enter 15 as a test
    > value - try different numbers to confirm that test works - If it does,
    > then I think you've not provided the entire code here for me (perhaps
    > anyone else) to give a full and proper answer/suggestion.
    >
    > Does any of the above help?
    > randelld

    R.G. Vervoort Guest

  5. #4

    Default Re: calling variable in onchange function

    Place_Selected('naam_keuze.value')

    you have passed the value of a javascript, this can't work, you have to
    explicitely write the value or a php variable, because you are in a php
    statement (server side, so no javascript value here).

    Savut

    "R.G. Vervoort" <roy.vervoort@royvervoort.nl> wrote in message
    news:407dd2d3$0$570$e4fe514c@news.xs4all.nl...
    > it works great, as long as the number (15 or ...) is an id in the
    > database.
    > i just will not accept the "." (dot) in the line
    >
    >
    >
    > "Reply Via Newsgroup" <reply-to-newsgroup@please.com> schreef in bericht
    > news:J9kfc.121495$Ig.78826@pd7tw2no...
    >> R.G. Vervoort wrote:
    >>
    >> > I am using a javafunction (onclick in select) in which i am calling a
    >> > function in php (thats why i send this to both php and javascript
    >> > newsgroups).
    >> >
    >> > in the onclick i call the function "Place_Selected" with the value from
    > the
    >> > select (naam_keuze.value)
    >> >
    >> > in the function the value becomes the $zoek_id and searches in the
    > database
    >> > for the record with the id of $zoek_id
    >> >
    >> > the naam_keuze.value does not give the value to $zoek_id
    >> >
    >> > When i replace naam_keuze.value for a number (15) i works great.
    >> >
    >> > WHAT AM I DOING WRONG?
    >> >
    >> >
    >> > This is my code
    >> >
    >> >
    >> >
    >> > Function Place_Selected($zoek_id)
    >> > {
    >> > include("data.php");
    >> > $link=mysql_connect($db_host, $username, $password) or die("Database
    >> > error!");
    >> > mysql_select_db($database , $link)or die("Couldn't open $db:
    >> > ".mysql_error());
    >> > $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");
    >> >
    >> > if ($sql)
    >> > {
    >> > while($blah2 = mysql_fetch_array($sql))
    >> > {
    >> > $newsid = $blah2['id'];
    >> > $sticky = $blah2['naam'];
    >> > }
    >> > }
    >> > return("document.form.achternaam.value='$sticky'") ;
    >> > }
    >> >
    >> >
    >> > <select id=naam_keuze size=1 name=keuze style=visibility:hidden
    >> >
    > onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
    >> > =naam_keuze.value;>
    >> > <option value=0>Kies
    >> > $options
    >> > </select>
    >> >
    >> > Thanks for suggestions
    >> >
    >> > roy
    >> >
    >> >
    >>
    >> I don't see how it could work, even with a numeric value of 15... What
    >> version of PHP are you using?
    >>
    >> Here's why I think it shouldn't work...
    >>
    >> Javascript is client side - PHP is server side... thus, you attempt to
    >> call Place_Selected (PHP code) in your onChange event - This won't
    >> happen unless you hava a javascript function with that name that submits
    >> the form contents to the server via a FORM POST or GET...
    >>
    >> Also... The value for your select box should I believe end up in
    >> $_POST['keuze'] in PHP when the form is submitted...
    >>
    >> And... return("document.form.achternaam.value='$sticky'") ;
    >> Again, you've got your knickers in a twist - the return statement will
    >> not return a value into achternaam like I think you expect... I really
    >> think you are misunderstanding how the two technologies fit together...
    >>
    >> If you are sure that your test will work when you enter 15 as a test
    >> value - try different numbers to confirm that test works - If it does,
    >> then I think you've not provided the entire code here for me (perhaps
    >> anyone else) to give a full and proper answer/suggestion.
    >>
    >> Does any of the above help?
    >> randelld
    >
    >
    Savut Guest

  6. #5

    Default Re: calling variable in onchange function

    ok

    I can see that it is a problem (for me)

    but....

    I can call a php function (with the ". ...... .") in the onchange (wich is
    javascript as i believe), is it not possible to call the javascript into a
    php function or to decalare a variable and the call it in the function
    (since it is possible to put a variable in the function wich works).

    thanks anyway

    Roy



    "Savut" <webki@hotmail.com> schreef in bericht
    news:GjAfc.27047$vF3.1605768@news20.bellglobal.com ...
    > Place_Selected('naam_keuze.value')
    >
    > you have passed the value of a javascript, this can't work, you have to
    > explicitely write the value or a php variable, because you are in a php
    > statement (server side, so no javascript value here).
    >
    > Savut
    >
    > "R.G. Vervoort" <roy.vervoort@royvervoort.nl> wrote in message
    > news:407dd2d3$0$570$e4fe514c@news.xs4all.nl...
    > > it works great, as long as the number (15 or ...) is an id in the
    > > database.
    > > i just will not accept the "." (dot) in the line
    > >
    > >
    > >
    > > "Reply Via Newsgroup" <reply-to-newsgroup@please.com> schreef in bericht
    > > news:J9kfc.121495$Ig.78826@pd7tw2no...
    > >> R.G. Vervoort wrote:
    > >>
    > >> > I am using a javafunction (onclick in select) in which i am calling a
    > >> > function in php (thats why i send this to both php and javascript
    > >> > newsgroups).
    > >> >
    > >> > in the onclick i call the function "Place_Selected" with the value
    from
    > > the
    > >> > select (naam_keuze.value)
    > >> >
    > >> > in the function the value becomes the $zoek_id and searches in the
    > > database
    > >> > for the record with the id of $zoek_id
    > >> >
    > >> > the naam_keuze.value does not give the value to $zoek_id
    > >> >
    > >> > When i replace naam_keuze.value for a number (15) i works great.
    > >> >
    > >> > WHAT AM I DOING WRONG?
    > >> >
    > >> >
    > >> > This is my code
    > >> >
    > >> >
    > >> >
    > >> > Function Place_Selected($zoek_id)
    > >> > {
    > >> > include("data.php");
    > >> > $link=mysql_connect($db_host, $username, $password) or die("Database
    > >> > error!");
    > >> > mysql_select_db($database , $link)or die("Couldn't open $db:
    > >> > ".mysql_error());
    > >> > $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");
    > >> >
    > >> > if ($sql)
    > >> > {
    > >> > while($blah2 = mysql_fetch_array($sql))
    > >> > {
    > >> > $newsid = $blah2['id'];
    > >> > $sticky = $blah2['naam'];
    > >> > }
    > >> > }
    > >> > return("document.form.achternaam.value='$sticky'") ;
    > >> > }
    > >> >
    > >> >
    > >> > <select id=naam_keuze size=1 name=keuze style=visibility:hidden
    > >> >
    > >
    onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
    > >> > =naam_keuze.value;>
    > >> > <option value=0>Kies
    > >> > $options
    > >> > </select>
    > >> >
    > >> > Thanks for suggestions
    > >> >
    > >> > roy
    > >> >
    > >> >
    > >>
    > >> I don't see how it could work, even with a numeric value of 15... What
    > >> version of PHP are you using?
    > >>
    > >> Here's why I think it shouldn't work...
    > >>
    > >> Javascript is client side - PHP is server side... thus, you attempt to
    > >> call Place_Selected (PHP code) in your onChange event - This won't
    > >> happen unless you hava a javascript function with that name that
    submits
    > >> the form contents to the server via a FORM POST or GET...
    > >>
    > >> Also... The value for your select box should I believe end up in
    > >> $_POST['keuze'] in PHP when the form is submitted...
    > >>
    > >> And... return("document.form.achternaam.value='$sticky'") ;
    > >> Again, you've got your knickers in a twist - the return statement will
    > >> not return a value into achternaam like I think you expect... I really
    > >> think you are misunderstanding how the two technologies fit together...
    > >>
    > >> If you are sure that your test will work when you enter 15 as a test
    > >> value - try different numbers to confirm that test works - If it does,
    > >> then I think you've not provided the entire code here for me (perhaps
    > >> anyone else) to give a full and proper answer/suggestion.
    > >>
    > >> Does any of the above help?
    > >> randelld
    > >
    > >
    >

    R.G. Vervoort Guest

  7. #6

    Default Re: calling variable in onchange function

    R.G. Vervoort wrote:
    > ok
    >
    > I can see that it is a problem (for me)
    >
    > but....
    >
    > I can call a php function (with the ". ...... .") in the onchange (wich is
    > javascript as i believe), is it not possible to call the javascript into a
    > php function or to decalare a variable and the call it in the function
    > (since it is possible to put a variable in the function wich works).
    >
    > thanks anyway
    >
    > Roy
    >
    LET US GET THIS STRAIGHT (and I'm sorry I'm shouting here) BUT YOU
    CANNOT UNDER NO CIRCUMSTANCES CALL PHP CODE USING AN ONCHANGE EVENT
    USING THE CODE YOU HAVE IN YOUR ORIGINAL POST (I've copied a line of the
    offending code below).

    <select id=naam_keuze size=1 name=keuze style=visibility:hidden
    onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
    =naam_keuze.value;>
    <option value=0>Kies
    $options
    </select>

    The code contained in the onChange event is expected to be javascript -
    NOT PHP.

    I'll say that again...

    The code contained in the onChange event is expected to be javascript -
    NOT PHP.


    Your web browser does not process PHP - It can use form methods GET and
    POST to communicate with a server, true, but the methods you have used
    above WILL NOT WORK.

    I'm not saying MIGHT - I'm not saying MAYBE - I'm not saying its a grey
    area... I AM DEFINITE, I HAVE NO DOUBT.... PHP is server side - an
    onChange event only has access to client side actions. The only link
    between the two is a POST or a GET method and from the code I see in
    your original post, I don't see this occuring.

    Unless you make your code available, either here in a post or via a url,
    folk are unlikely to be able to help you. You are wasteing your time.

    You mention that some numeric input works for you and I say that is
    rubbish... thrash... garbage. If you are adamant that it does work then
    you are either mistaken, have a bug in your code and getting the result
    from something other than PHP or you have not provided enough of source
    code for anyone here to help to show how the data is being sent from
    your client, to the server, and back, to give you this result you claim.

    I honestly don't mean to offend, but while you persisted in making a
    false claim and I needed to clear it up... I'll honestly do my best to
    help though...

    regards
    randelld
    Reply Via Newsgroup Guest

  8. #7

    Default Re: calling variable in onchange function

    I too have the same problem.. Didn't you get any solution for this problem? Then how i could calling variable from php to javascript.
    Reesha Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139