Jump to content

[SOLVED] Call drop list from a function


harchew

Recommended Posts

I created a function name createTextField() to display all my textfield.

 

function createTextField($name,$value) {

    return "<input type=\"text\" name=\"$name\" value=\"$value\" class=\"txtField\">";

}

 

I declared the function with a variable : $input_addcat = createTextField('addcat',NULL); and display it using

echo $input_addcat. its works perfectly for this case. However when I tired using the same function for drop list :

 

function createList()

{

return "<select name=\"a\">

  for ($a=0; $a < 10; $a++){

<option value=\"a\">1</option>

  }

</select>";

}

decalre it by $list  = createList(); and display it using echo $list;

The drop list only show a single value. For some reason the for loop didn't work in the function. Any solution to it? I have been working all night long just to figure out a solution for it. Really appreciate your help. Thank you in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/68276-solved-call-drop-list-from-a-function/
Share on other sites

because you're returning a string which has the words for($a...etc in it. Not php code. You need to use the for loop to append strings to the returning string.

 

Thanks for the quick reply. I understand what you mean, I tried various way including declare it as a variable instead of string but still can't work. Perhaps you can show me an example. Thank U....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.