Jump to content


Photo

JavaScript question


  • Please log in to reply
2 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 08 July 2006 - 06:33 AM

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%

<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>

here is what i think the JS should look like:

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

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

any ideas?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 08 July 2006 - 06:49 AM

wrong forum, try your luck here http://www.phpfreaks.../board,6.0.html
;)

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 08 July 2006 - 07:02 AM

try
<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>

Moving to JS forum
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users