function - Calling php query in javascript -
so have jscript creates new text input , drop-down select each addition. first 1 have on page fine since php function gets called on page. issue have drop-down not populated query since not have javascript function calling php function. im not sure how add in. here jscript function.
var counter = 1; var limit = 45; function addinput(divname){ if (counter == limit) { alert("you have reached limit of adding " + counter + " inputs"); } else { var newdiv = document.createelement('div'); newdiv.innerhtml = "hop " + (counter + 1) + " <br><input type='text' name='myinputs[]'><br>" + "type "+ (counter + 1) + " <br><select name='myinputs2[]' data-rel='chosen'><?php query() ?></select>" ; document.getelementbyid(divname).appendchild(newdiv); counter++; } }
here html. drop-down (the first drop-down) populated.
<?php include_once 'dropfunc2.php'; connect (); ?> <script src="js/addinput.js" language="javascript" type="text/javascript"></script> <form method="post"> <div id="dynamicinput"> hop 1<br><input type="text" name="myinputs[]"><br> type 1<br><select name="myinputs2[]" data-rel="chosen"><?php query() ?></select> </div> <input type="button" value="add hop" onclick="addinput('dynamicinput');"> <input type="submit" value="submit"> </form>
now have tried doing have found on site , making jscript .php page , adding header("content-type: application/javascript"); function breaks , not add more inputs. addinputs not defined jscript error.
put php code retrieve data in separate file , call script ajax. can either send formatted html or json array parse through , populate tags in javascript.
this out if you're new ajax , don't want use jquery: http://www.w3schools.com/ajax/default.asp
if want use jquery, check out: http://api.jquery.com/jquery.ajax/
Comments
Post a Comment