1

I found some similar questions but I couldnt figure out :(

This is my jQuery:

<script>
function avukat_change()
{
        if (jQuery("#AVUKATNO").val()=='14')
            jQuery("#fieldatamatarihi").show(1000);  
        else  
            jQuery("#fieldatamatarihi").hide(1000);
}

And I would like to replace '14' with this:

$UserID = scf_user_userid()
Loofer
  • 6,841
  • 9
  • 61
  • 102
cvdogan
  • 166
  • 1
  • 1
  • 13
  • Is `scf_user_userid()` a PHP or JS function? – BenM Apr 09 '14 at 09:56
  • 1
    HTTP protocol + JSON. – moonwave99 Apr 09 '14 at 09:57
  • where is `scf_user_userid()` defined? Can you run it in the same file or it is somewhere on the server-side. – d.raev Apr 09 '14 at 10:01
  • 1
    You have three ways to do it: 1. Make webserver to pass .js files to PHP for parsing (not good idea). 2. Embed a small script in the .php file where you could define JS variables with values of PHP variables `var x = '';` and then call `func(x)` from JS file. 3. Make AJAX calls to request data from the server as @moonwave99 said (HTTP + JSON). I always bet on 3. where it is acceptable and use 2. for small tasks. – Rolice Apr 09 '14 at 10:04
  • 1
    It defined in the same file. And problem is solved. Thanks guys. – cvdogan Apr 09 '14 at 10:10

4 Answers4

1

This should do:

function avukat_change()
{
    if (jQuery("#AVUKATNO").val()=='<? echo scf_user_userid();?>') 
       jQuery("#fieldatamatarihi").show(1000); 
    else  
       jQuery("#fieldatamatarihi").hide(1000);
}
csharpwinphonexaml
  • 3,659
  • 10
  • 32
  • 63
1
<script>
function avukat_change()
{
    if (jQuery("#AVUKATNO").val() == '<?php echo scf_user_userid(); ?>') 
       jQuery("#fieldatamatarihi").show(1000); 
    else  
       jQuery("#fieldatamatarihi").hide(1000);
}
</script>
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
0
<script>
function avukat_change(){
    if (jQuery("#AVUKATNO").val()==<?php echo $UserID = scf_user_userid(); ?>)  jQuery("#fieldatamatarihi").show(1000); else  jQuery("#fieldatamatarihi").hide(1000);
}
Rohit Subedi
  • 560
  • 3
  • 13
0

Or a quicker solution would be to do it shorthand.

<script>
function avukat_change()
{
    if (jQuery("#AVUKATNO").val()=='<?=scf_user_userid()?>') 
       jQuery("#fieldatamatarihi").show(1000); 
    else  
       jQuery("#fieldatamatarihi").hide(1000);
}
</script>
scottevans93
  • 1,119
  • 1
  • 9
  • 25