下拉式选单的价值

时间:2018-10-09 15:11:23

标签: javascript php html

我有register.php。当该人提交表单时,该值将过帐并插入数据库。我有要插入数据库的用户名,电子邮件,国家/地区和密码。

我的国家在下拉列表中。

这是我已经完成的工作。

# Create composite dataset by combining all files
compositeDataD <- rbind(fileA,fileB,fileC)


# Get unique (drug, target) pairs
# Connect Drug Names and Target Gene Symbols into one vector of pairs
compositeDataD <- na.omit(compositeDataD)
DrugTargetPairsD <- paste(compositeDataD$Drug,compositeDataD$Target,sep="")
uniquePairsD<-unique(DrugTargetPairsD)

PairsA <- DrugTargetPairsD[1:nrow(na.omit(fileA))]
PairsB <- DrugTargetPairsD[1:nrow(na.omit(fileB))]
PairsC <- DrugTargetPairsD[1:nrow(na.omit(fileC))]

# Create binary matrix for unique (drug, target) pairs 


binaryA <- as.numeric(uniquePairsD %in% PairsA) # This function returns a binary value for each unique (Drug, Target) Pair compared with the content of file1
binaryB <- as.numeric(uniquePairsD %in% PairsB)
binaryC <- as.numeric(uniquePairsD %in% PairsC)


table33 <- data.table(Pairs=uniquePairsD,
                     fileA=binaryA,fileB=binaryB,
                     fileC=binaryC)

现在我有这个国家/地区下拉列表。该国家/地区将以“ Australia”之类的字符串存储。

<div class="form-group">
  <input id="username" type="text" class="form-control" name="username" 
  placeholder="Username" value="<?php if(isset($_POST['username'])) { echo $_POST['username']; } ?>" required autofocus>
</div>

如果设置了_POST变量,如何设置_POST变量的下拉列表的初始值?

编辑

<div class="form-group ui selection dropdown ">
      <input type="hidden" name="country" class="form-control"> 
      <i class="dropdown icon"></i>
      <div class="default text">Select a country</div>
      <div class="menu">
        <div class="item" data-value="af"><i class="af flag"></i>Afghanistan</div>
        <div class="item" data-value="ax"><i class="ax flag"></i>Aland Islands</div>
        <div class="item" data-value="al"><i class="al flag"></i>Albania</div>
        <div class="item" data-value="dz"><i class="dz flag"></i>Algeria</div>
        <div class="item" data-value="as"><i class="as flag"></i>American Samoa</div>
        <div class="item" data-value="ad"><i class="ad flag"></i>Andorra</div>
        <div class="item" data-value="ao"><i class="ao flag"></i>Angola</div>
        <div class="item" data-value="ai"><i class="ai flag"></i>Anguilla</div>
        <div class="item" data-value="ag"><i class="ag flag"></i>Antigua</div>
        <div class="item" data-value="ar"><i class="ar flag"></i>Argentina</div>
        <div class="item" data-value="am"><i class="am flag"></i>Armenia</div>
        <div class="item" data-value="aw"><i class="aw flag"></i>Aruba</div>
        <div class="item" data-value="au"><i class="au flag"></i>Australia</div>
        ...
      </div>
    </div>

1 个答案:

答案 0 :(得分:0)

要设置初始值,请将选定属性指定为适当的选项,如下所示:

<?php

     $gender = $_POST['gender']; //get value from post

?>

<select name="gender" class="form-group ui selection dropdown" id="select">
      <option value="">Select a country</option>
      <option value="Afghanistan" <?= ($gender=="Afghanistan"?"selected":"") ?>>Afghanistan</option>
      <option value="Albania" <?= ($gender=="Albania"?"selected":"") ?>>Albania</option>
      <option value="Algeria" <?= ($gender=="Algeria"?"selected":"") ?>>Algeria</option>
      <option value="American Samoa" <?= ($gender=="American Samoa"?"selected":"") ?>>American Samoa</option>
      <option value="Andorra" <?= ($gender=="Andorra"?"selected":"") ?>>Andorra</option>
      ...

</select>