amg182 Posted September 2, 2011 Share Posted September 2, 2011 Hi Guys. I am trying to call variables inside a function: Here is what i am trying to do, but doesnt like it? function disable($var1,$var2) { if ( $var1 == "" ) { $var2="disabled"; } } disable("$form", "$select"); Cheers Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 2, 2011 Share Posted September 2, 2011 What do you mean by "I am trying to call variables inside a function". In the code you posted above you are passing two values into the function as two parameters. Then, based upon the value of the first parameter, you are modifying the value of the 2nd parameter. And, that's it. You don't apss anything back from the function. What exactly are you trying to accomplish with his function. It looks like you are using it to determine if a form field is disabled or not, but I'd be interested in seeing how you plan to use it. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2011 Share Posted September 2, 2011 Define "doesn't like it", please. What's supposed to happen, versus what actually happens. Quote Link to comment Share on other sites More sharing options...
amg182 Posted September 2, 2011 Author Share Posted September 2, 2011 thanks for replies. I have a form containg up to 13 select fields(comboboxes). I am writing an if statement to say if the comboboxs contains a value then disable it, otherwise leave it enabled. Here is the actual code i am working with: if ( $select1 != "" ) { $cond="disabled"; } else { $cond='onChange="filters.submit();"'; } ..... <form name="filters" id="filters" action="index.php?" method="post"> <td><Select name='select1' id=" <?php echo $cond; ?>> <option value..... Rather than write this if statement 13 times, i thought i would use a function instead. Sorry i over complicated things earlier, thought i would strip the code down to make it easier to interpret.(Done the opposite probably) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.