JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 2nd, 2003, 07:30 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Unhappy dynamic script not working

Hi! I am attempting to make a form element appear based on a user selection from a dropdown but not having any luck. I hope y'all can help me! Here is what I have so far:
PHP Code:
<?
# The code for the form
function new_submission_form() {
  
$form = <<<EOH
\r
<script type="text/javascript" language="JavaScript">
<!--
function changeIt() 
{
  if (document.submissionform.type
[document.submissionform.type.selectedIndex].value == "poll") {
  if(document.submissionform.description.style.displ  ay != 'none') 
{
    document.submissionform.description.style.display = 'none';
    document.submissionform.question.style.display = 'inline';
    document.submissionform.answer
[].style.display = 'visible';
    descquest.innerText = "Poll Question";
  
}
  else 
{
    document.submissionform.description.style.display = 'visible';
    document.submissionform.question.style.display = 'none';
    document.submissionform.answer
[].style.display = 'none';
    descquest.innerText = "Submission Description";
  
}
  
}
}
//-->
</script>
<p><font size="3">
<table width="100%" cellpadding="2" cellspacing="0" border="1" bordercolor="#C0C0C0">
<tr><td>
<form name="submissionform" method="post" action="/content/">
<input type="hidden" name="action" value="do_post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td align="left"><b>Submission Type:&nbsp;</b></td>
<td>
<select name="type" id="type" onChange="changeIt()">
<option value="article">Article</option>
EOH;
  
session_start();
  
# check if we have an administrator
  
if ($_SESSION[$sess_prefix.'user_level'] == '0') {
  
# if so, add the poll option
    
$form .= <<<EOH
<option value="poll">Poll</option>
EOH;
}
  
$form .= <<<EOH
<option value="story">Story</option>
<option value="poem">Poem</option>
</select>
</td>
</tr>
<tr valign="top">
<td align="left"><b>Submission Title:&nbsp;</b></td>
<td><input type="text" name="title" size="45" /></td>
</tr>
<tr valign="top">
<td align="left"><span id="descquest">Submission Description</span>:&nbsp;</td>
<td>
<input type="text" name="description" id="description" size="45" style="display: inline;" />
<input type="text" name="question" id="question" size="45" value="test" style="display: none;" />
</td>
</tr>
<td align="left">Allowed HTML Tags&nbsp;</b></td>
<td><p></p>;<br />;<b></b>;<i></i></td>
</tr>
<tr valign="top">
<td align="left"><b>Submission Content:&nbsp;</b></td>
<td><textarea name="content" cols="40" rows="15" wrap="soft"></textarea></td>
</tr>
<tr valign="top">
<td align="left">&nbsp;</td>
<td><input type="submit" name="submit" value="Post"><input type="reset" name="reset" value="Clear"></td>
</tr>
</table>
</td></tr>
</table>
</form>
</font>
</p>
<p><center>All fields in <b>bold</b> are required.</center></p>
<p>
<small>
<b>Please Note:</b>
<br />
Click the "Post" button <i>only <b>once</b></i>. It may take some time before your browser reacts due to the speed of your connection.
<br />
<font color="red">We neither support nor accept the posting of previously copyrighted material <i>unless</i> permission has been granted by the author(s).</font>
<br />
All new submissions are subject to approval by an administrator.
</small>
</p>
\r
EOH;
  
# give us back the form
  
return $form;
}
?>
<html>
<head>
<title>New Submission</title>
</head>
<body>
<h1>New Submission</h1>
<!--display the form-->
<?=new_submission_form?>
</body>
</html>


Many thanks in advance!
Joe of 4Life
__________________
Check out 4Life today!

Last edited by Joe4JC : September 2nd, 2003 at 07:38 PM.

Reply With Quote
  #2  
Old September 5th, 2003, 07:19 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
MmmK - there's a few things wrong here.
a) Be careful with your variable naming. You have used a few words that are normally considered reserved words. (type, description, etc)
b) For IE, the show/hide property is called "visibility", not display.
c) For IE, "hidden" or "visible" are the visibility property values. Don't use "none".
d) I don't follow your logic in the Javascript. Shouldn't the ELSE statement belong to the "is value == 'poll'" IF statement?

Reply With Quote
  #3  
Old September 6th, 2003, 10:10 AM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thank you, stumpy! I currently I am trying to get this working with Mozilla 1.4. (I'm on FreeBSD so I can't use IE.) I'll try and answer your questions to the best of my ability.

a.) Ok, thanks for the tip; i'll be sure to change that!
b.) Allright, I'll see if that will work.
c.) [See above.]
d.) Yes, I accidently misplaced a "}".

Please note that I do not normally write JavaScript, so I am not 100% sure of what I am doing.

Thank you very much for your kind and helpful response!
Joe

Reply With Quote
  #4  
Old September 6th, 2003, 10:22 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
No worries mate - I actually grabbed your code, and made the changes i suggested and got it going, but, unfortunately, only on IE (i didn't try mozilla, etc). From memory, the show/hide methods are called something different to IE in Mozilla.... surely there's a ref manual you can get the official naming from.

Reply With Quote
  #5  
Old September 11th, 2003, 03:05 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Ok, I finnaly fixed it for Mozilla. If you want the code, just leave a message here cause I'll have to pack it into a separate file.

Cheers,
Joe of 4Life
jc4life.org

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > dynamic script not working


Thread Tools  Search this Thread 
Search this Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway