close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

populate a text field upon a dropdown change

Thread began 5/17/2015 8:23 am by JBWebWorks | Last modified 5/19/2015 12:19 pm by Ray Borduin | 1359 views | 2 replies |

JBWebWorks

populate a text field upon a dropdown change

Have a membership db and recordset with column FirstName, LastName and GHIN_number
On form dropdown, i have array, FirstName and LastName
When a member is signing up for a game, they go to this form and select their name for the dropdown array [FirstName LastName]
I want to populate a text field with their GHIN_number, based on their choice in the dropdown of their name.

Then when their choice is made and they click Submit, I want to insert the FirstName, LastName and GHIN_number into another db table called Saturday Game.

My current code for the dropdown

php:
<?php


if($_SERVER["REQUEST_METHOD"] == "POST")     {

    foreach(
$_POST as $key => $val) {

        if(
is_array($_POST[$key])) $_POST[$key] = implode(", "$_POST[$key]);

    }

}

?>

<?php $selected explode(", "ValidatedField("index_225","player1")); ?><form  action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
    
      <label for="player1"><strong>Your Name:</strong></label>
      <select name="player1[]" id="player1">
        <option value="" selected="selected">Select From Dropdown</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rs_members['FirstName']?> <?php echo $row_rs_members['LastName']?><?php if(in_array($row_rs_members['FirstName']." ".$row_rs_members['LastName'], $selected)) echo("selected=\"selected\""); ?>><?php echo $row_rs_members['FirstName']?> <?php echo $row_rs_members['LastName']?></option>
        <?php
} while ($row_rs_members mysql_fetch_assoc($rs_members));
  
$rows mysql_num_rows($rs_members);
  if(
$rows 0) {
      
mysql_data_seek($rs_members0);
      
$row_rs_members mysql_fetch_assoc($rs_members);
  }
?>
      </select>
      <?php
if (ValidatedField('index_225','index_225'))  {
  if ((
strpos((",".ValidatedField("index_225","index_225").","), "," "1" ",") !== false || "1" == ""))  {
    if (!(
false))  {
?>
        <span class="stylered">Name required</span>
        <?php //WAFV_Conditional index.php index_225(1:)
    
}
  }
}
?>
<br />

  <?php
if (ValidatedField('index_276','index_276'))  {
  if ((
strpos((",".ValidatedField("index_276","index_276").","), "," "1" ",") !== false || "1" == ""))  {
    if (!(
false))  {
?>
    <span class="stylered">You are already signed up for Saturday</span>
    <?php //WAFV_Conditional index.php index_276(3:)
    
}
  }
}
?>
<br />
      <label for="email1"><strong>Email Confirmation </strong></label>
      <select name="email1" id="email1">
        <option value="" <?php if (!(strcmp("", (ValidatedField("index_225","email1"))))) {echo "selected=\"selected\"";} ?>>Select your Name if you want an email confirmation</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rs_members['EmailAddress']?>"<?php if (!(strcmp($row_rs_members['EmailAddress'], (ValidatedField("index_225","email1"))))) {echo "selected=\"selected\"";} ?>><?php echo $row_rs_members['FirstName']; ?> <?php echo $row_rs_members['LastName']?> </option>
<?php
} while ($row_rs_members mysql_fetch_assoc($rs_members));
  
$rows mysql_num_rows($rs_members);
  if(
$rows 0) {
      
mysql_data_seek($rs_members0);
      
$row_rs_members mysql_fetch_assoc($rs_members);
  }
?>
      </select>
      <br />
<br />

      <label for="tee1"><strong>Your Tee Choice:</strong></label>
      <select name="tee1" id="tee1">
        <option value="" selected="selected" <?php if (!(strcmp("", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>Select Your Tee</option>
        <option value="Gold" <?php if (!(strcmp("Gold", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>Gold</option>
        <option value="White" <?php if (!(strcmp("White", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>White</option>
        <option value="Blue" <?php if (!(strcmp("Blue", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>Blue</option>
      </select>
      <?php
if (ValidatedField('index_225','index_225'))  {
  if ((
strpos((",".ValidatedField("index_225","index_225").","), "," "2" ",") !== false || "2" == ""))  {
    if (!(
false))  {
?>
        <span class="stylered">Tee Required</span>
        <?php //WAFV_Conditional index.php index_225(2:)
    
}
  }
}
?>
<br />
      <br />
      <label for="pairing1"><strong>Pairing Request:</strong></label>
      <textarea name="pairing1" id="pairing1" cols="45" rows="5"><?php echo(ValidatedField("index_225","pairing1")) ?></textarea>
      <br />
      <br />
      <span><input type="submit" name="submit1" id="submit1" value="Submit Saturday Signup" /></span>
  </form>



I don't have the text field, GHIN_number in the form since i am not sure how to populate it based on their choosing their name in the select field.

Also, how to get the array of FirstName and LastName to insert into two columns?

Sign in to reply to this post

Ray BorduinWebAssist

The easiest way is probably to add the GHIN number to another property of the list options like: rel="<?php echo $row_rs_members['GHIN_number']?>"

Then you could add an onchange event to the list to take the rel attribute from the selected option and populate another form element.

I'd probably add a delimiter to the option value to use to split the first and last name on when the form is submitted to allow you to easily differentiate the first and last name.

This process is going to require some hand coding in both javascript (to populate the number) and php (to separate the first and last names) so I'd suggest a premier support ticket if you aren't familiar with these scripting languages.

Sign in to reply to this post
Did this help? Tips are appreciated...

JBWebWorks

Thanks Ray,
I was actually able to figure it out by using the FirstName,LastName,GHIN_number in the player1 select options and hidden fields for each. And then JavaScript to populate the hidden fields with an on change calling the function when the person chooses from the select drop down.

My code

php:
<script type="text/javascript">

function setSatsignup(opts) {
    var optArray = new Array;
    optArray = opts.split(",");
    var theForm = document.form1;
    var prodNameField = theForm.FirstName;
    var prodName1Field = theForm.LastName;
    var prodGHINField = theForm.GHIN_number;
    prodName1Field.value = optArray[1];
    prodGHINField.value = optArray[2];
    prodNameField.value = optArray[0];
    

}
</script>

<div id="form1_ProgressWrapper">
<?php $selected explode(", "ValidatedField("index_225","player1")); ?><form  action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
    
      <label for="player1"><strong>Your Name:</strong></label>
      <select name="player1[]" id="player1" onchange="setSatsignup(document.form1.player1[document.form1.player1.selectedIndex].value)">
        <option value="" selected="selected">Select From Dropdown</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rs_members['FirstName']?>,<?php echo $row_rs_members['LastName']?>,<?php echo $row_rs_members['GHIN_Number']; ?>"><?php echo $row_rs_members['FirstName']?> <?php echo $row_rs_members['LastName']?></option>
        <?php
} while ($row_rs_members mysql_fetch_assoc($rs_members));
  
$rows mysql_num_rows($rs_members);
  if(
$rows 0) {
      
mysql_data_seek($rs_members0);
      
$row_rs_members mysql_fetch_assoc($rs_members);
  }
?>
      </select>
      <?php
if (ValidatedField('index_225','index_225'))  {
  if ((
strpos((",".ValidatedField("index_225","index_225").","), "," "1" ",") !== false || "1" == ""))  {
    if (!(
false))  {
?>
        <span class="stylered">Name required</span>
        <?php //WAFV_Conditional index.php index_225(1:)
    
}
  }
}
?>
<br />

  <?php
if (ValidatedField('index_276','index_276'))  {
  if ((
strpos((",".ValidatedField("index_276","index_276").","), "," "1" ",") !== false || "1" == ""))  {
    if (!(
false))  {
?>
    <span class="stylered">You are already signed up for Saturday</span>
    <?php //WAFV_Conditional index.php index_276(3:)
    
}
  }
}
?>
<br />
      <label for="email1"><strong>Email Confirmation </strong></label>
      <select name="email1" id="email1">
        <option value="" <?php if (!(strcmp("", (ValidatedField("index_225","email1"))))) {echo "selected=\"selected\"";} ?>>Select your Name if you want an email confirmation</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rs_members['EmailAddress']?>"<?php if (!(strcmp($row_rs_members['EmailAddress'], (ValidatedField("index_225","email1"))))) {echo "selected=\"selected\"";} ?>><?php echo $row_rs_members['FirstName']; ?> <?php echo $row_rs_members['LastName']?> </option>
<?php
} while ($row_rs_members mysql_fetch_assoc($rs_members));
  
$rows mysql_num_rows($rs_members);
  if(
$rows 0) {
      
mysql_data_seek($rs_members0);
      
$row_rs_members mysql_fetch_assoc($rs_members);
  }
?>
      </select>
      <br />
<br />

      <label for="tee1"><strong>Your Tee Choice:</strong></label>
      <select name="tee1" id="tee1">
        <option value="" selected="selected" <?php if (!(strcmp("", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>Select Your Tee</option>
        <option value="Gold" <?php if (!(strcmp("Gold", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>Gold</option>
        <option value="White" <?php if (!(strcmp("White", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>White</option>
        <option value="Blue" <?php if (!(strcmp("Blue", (ValidatedField("index_225","tee1"))))) {echo "selected=\"selected\"";} ?>>Blue</option>
      </select>
      <?php
if (ValidatedField('index_225','index_225'))  {
  if ((
strpos((",".ValidatedField("index_225","index_225").","), "," "2" ",") !== false || "2" == ""))  {
    if (!(
false))  {
?>
        <span class="stylered">Tee Required</span>
        <?php //WAFV_Conditional index.php index_225(2:)
    
}
  }
}
?>
<br />
      <br />
      <label for="pairing1"><strong>Pairing Request:</strong></label>
      <textarea name="pairing1" id="pairing1" cols="45" rows="5"><?php echo(ValidatedField("index_225","pairing1")) ?></textarea>
      <br />
      <br /><input name="FirstName" id="FirstName" type="hidden" value="" /><input name="LastName" id="LastName" type="hidden" value="" /><input name="GHIN_number" id="GHIN_number" type="hidden" value="" />
      <span><input type="submit" name="submit1" id="submit1" value="Submit Saturday Signup" /></span>
  </form>
</div>
Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...