To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-14-2006, 03:05 PM   #1
K0108788
Member
 
Join Date: Mar 2006
Posts: 38
MYSQL+JS problem

Hi All,

I am trying to get the following code working. It is supposed to display a selection box for the project_ID and two read only text boxes for the project_name and project_desc. However the two read only boxes don't seem to display anything. The project_ID does display in the selection box. Any help appreciated.

PHP Code:
<?php
     $sql
= "SELECT student_ID, project_name FROM student_project";
     
$result = mysql_query($sql) or die ($sql . '<br />' . mysql_error());
     if (!
$result) {
             echo
'Query failed';
             exit;
     }
     
$optionsHTML = '';
     
$optionsJS      = "var projectData = new Array();\n";

     
$query = 'SELECT project_ID, project_name, project_desc FROM student_project';

     
$result = mysql_query($query) or die("error in query:" . mysql_error());

     function
jsSafe($str) {
     return
addslashes(htmlspecialchars(preg_replace("/[\n\r]+/",'', $str)));
}

     while(
$row = mysql_fetch_assoc($result)) {
       
$optionsHTML .= '<option value="'.$row['project_ID'].'">'.$row['project_ID'].'</option>';
       
$optionsJS .= sprintf('projectData[%d] = new Array("%s","%s");'."\n",
                      
$row['project_ID'],
                      
jsSafe($row['project_name']),
                      
jsSafe($row['project_desc']));
}

     echo
'<script type="text/javascript">';
     echo
$optionsJS;
     echo
'</script>';   
     echo
'<select onchange="v=this.options[this.selectedIndex].value;this.form.text1.value=projectData[v][0];this.form.text2.value=projectData[v][1];">';
     echo
$optionsHTML;
     echo
'</select>';
     echo
'<input type="text" name="text1" readonly="readonly" />';
     echo
'<input type="text" name="text2" readonly="readonly" />';

?>
Here is what I got from HTML View Source for <script type="text/javascript"> onwards:

<script type="text/javascript">var projectData = new Array();
projectData[18] = new Array("TEST1","TEST DESC1");
</script><select onchange="v=this.options[this.selectedIndex].value;this.form.text1.value=projectData[v][0];this.form.text2.value=projectData[v][1];"><option value="18">18</option></select><input type="text" name="text1" readonly="readonly" /><input type="text" name="text2" readonly="readonly" /></td>
</table>
<br>
<input type="submit" name="submit" value="Join Project">
K0108788 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 06:38 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.