Jump to content

Archived

This topic is now archived and is closed to further replies.

glenelkins

JavaScript question

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?

Share this post


Link to post
Share on other sites
wrong forum, try your luck here http://www.phpfreaks.com/forums/index.php/board,6.0.html
;)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.