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
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....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.