javascript - Passing id element to database using ajax -


i have following code, works:

<script> function showuser(str) { if (str=="") { document.getelementbyid("txthint").innerhtml=""; return; }  if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) {   document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext;  } } xmlhttp.open("get","getuser.php?q="+str,true); xmlhttp.send(); } </script>  <body>  <?php include 'db_connector.php';  $result = mysqli_query($con,"select * scope");  while($row = mysqli_fetch_array($result)) {  $row['name'];  echo  "<div class='toggle-btn-grp cssonly'> <div><input type='radio' name='os' value=".$row['name']." id='myradio' onchange='showuser(this.value)'>      <label  class='toggle-btn'>".$row['name']."</label></div>  </div>";              }    ?>   <p>click "try it" button display value of radio button.</p>   <button onclick="myfunction()">try it</button>   <div id="txthint"></div>   </body> 

now want repeat same process, using radio button time want value of new radio button ever user selects <div id="txthint"></div>.

is possible @ all??

here backend getuser.php file:

<?php $q = strval($_get['q']);  echo "<center><b>scope ".$q."</b></center><br><br>";  include 'db_connector.php';  mysqli_select_db($con,"ajax_demo"); $sql="select * os scope = '".$q."'"; $result = mysqli_query($con,$sql);  while($row = mysqli_fetch_array($result)) {    echo "<a href=''>id: ".$row['id']."</a><br>"; echo "<a href=''>name: ".$row['name']."</a><br><br>";  }  mysqli_close($con);   ?> 

any advice appreciated. in advance.

you should @ answer.

stackoverflow answer: getting selected text in browser, cross-platform

from wrote, i'm guessing want make new radio button based on text user selects contents of txthint div.

the problem whatever employ normal javascript might difficult in cross browser way.

and maybe you're learning javascript, try using jquery, specially ajax...it's awesome!

the following answer suggests use of jquery plugin , wrapselection plugin in cross browser supported way!


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -