Jump to content

Recommended Posts

Hi

Not sure if anyone can help on this here

What i want to be able to do, is after the following code had run to generate the drop down list of email history, i want to set some JS so when the user clicks one of the emails in the history, it automatically puts it into a text box. I have an idea of how to do this but not 100%

[code]
<select name="emailhistory">
  <?
  $sql = "SELECT * FROM email_history WHERE user_id=" . $userid;
  $result = mysql_query($sql) or die (mysql_error());

  while ($emailHistory = mysql_fetch_array($result)) {
    ?>
    <option><? echo $emailHistory['email']; ?></option>
    <?
  }
  ?>
</select>
[/code]

here is what i think the JS should look like:

[code]
<select name="emailhistory" onclick="return ChooseHistoryEmail()">

<SCRIPT LANGUAGE="JavaScript">
  function ChooseHistoryEmail() {
    chosenemail = document.formname.emailhistory.option[0];
    document.formname.textboxname.value = chosenemail;
  }
</SCRIPT>
[/code]

any ideas?
Link to comment
https://forums.phpfreaks.com/topic/14006-javascript-question/
Share on other sites

try
[code]
<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>Sample</title>
<SCRIPT LANGUAGE="JavaScript">
  function ChooseHistoryEmail(val) {
    document.getElementById("textboxname").value = val;
  }
</SCRIPT>
</head>
<body>
<form name="formname" >
<select name="emailhistory" onchange="ChooseHistoryEmail(this.value)">
        <option value="0">'SELECT-</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>  </select>
<input type="text" name="textboxname" id="textboxname" size="5">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>[/code]

Moving to JS forum
Link to comment
https://forums.phpfreaks.com/topic/14006-javascript-question/#findComment-54695
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.