php - Select box verify with javascript -


i trying ask users verify select option choice using javascript alert. if user clicks continue delete choice, if click cancel return page. have php code drop down done, populated code database , user can select value delete. dont know javascript must ask verification.

my php code far is:

<select> <option selected name="offer">click here choose item</option> <? $sql = "select * items"; $res = $dbi->dbdo($sql); while( $row = mysql_fetch_assoc($res) ) {  print_r('<option>'.$row['name'].'</option>'); } ?> </select>  <input type="submit" value="delete" class="button-delete" onclick="submit()"></input> 

so there should javascript function called submit, before submit confirmation must happen.

thanks

    function submit() {      var sel=document.getelementbyname("offer").value;      var r=confirm("do want delete selected option");      var xmlhttp;      if(r==true)      {          if(window.xmlhttprequest)          {              xmlhttp=new xmlhttprequest();          }          xmlhttp.onreadystatechange=function()          {             if(xmlhttp.readystate==4)             {                  alert(xmlhttp.responsetext);             }          }          xmlhttp.open("get","hello.php?option="+sel,true);          xmlhttp.send();      } } 

now here file hello.php delete selected option

<? $sql = "delete items itemvalue=".$_request["option"]; if($sql) {    echo("item deleted"); } ?> 

the echo in php file shown alert.

click answer if


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -