tags:

views:

78

answers:

1

i have added html elements at run time using append Code:

function addFormField() {       
    $("#inputss").append("<strong>asif</strong>"); }

but how can i add a select element at run time that looks like this..

PHP Code:

<select name="pre_req"  id="pre_req" class="inputs"  
value=<? if($this->uri->segment(2)=='update') echo $results['pre_req']?>> 

<option value='None'>None</option>             

<? foreach($combo1 as $row)
echo "<option value=$row[sub_name]>$row[sub_name</option>";
?>

</select>  
+2  A: 

If you want to have client-side (ie. JavaScript code) that adds an HTML element you obviously cannot have PHP code there. You would need to have a web page written in PHP that returns the HTML you want for the element you want and then insert that element using jQuery. jQuery has a really handy method for this $.load(), but you need to create an element first. Eg.

 $("#inputss").append("<div id='placeholder'></div>");
 $("#placeholder").load('someAjaxService.php')
Evgeny
thnks..i did this..$select="<p><select name=pre_req id=pre_req class=inputs><option value=None>None</option>"; foreach($combo1 as $row) $select.= "<option value=$row[sub_name]>$row[sub_name]</option>"; $select.="</select></p>";and thenonClick="addFormField('<?=$select?>')its working now
mysterious