SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change form elements?

    i am making an admin and demending on what you are adding i need different information

    i have this select:
    HTML Code:
    Project Type:
    	<select id="port_type" name="port_type">
    	<option id="web">Website</option>
    	<option id="flash">Flash</option>
    	<option id="image">Image</option>
    	</select>
    and if web is selected i need this to be displayed:
    HTML Code:
    Pop-Up URL:
    	<input type="text" name="des" id="des" size="35" value="http://" />
    else if flash or image is selected i need this to be displayed:

    HTML Code:
    	Pop-Up File:
    	  	<input name="popup" type="file" id="popup" size="20">

    THANKS!!!!
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    .* draziW tnioPetiS *. bronze trophy
    Join Date
    Jun 2004
    Location
    "Then I figure the most good good guy will win."
    Posts
    1,666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recently posted some code here (#2 post)

    A user selects a dropdown selection and other form elements pop-up... I think it may be of use to you.

    Cheers,
    Micky

  3. #3
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i did it but its not seeing my form element as an object

    heres my code:
    Code:
    function show_hide_pop() {
       var p_type=document.form1.port_type.options[document.form1.port_type.selectedIndex].value;
       if(p_type == 'web') {
         var site = document.getElementById('des');
    	 var popup = document.getElementById('popup');
         site.style.display = 'block';
    	 popup.style.display = 'none';
       } else {
         var site = document.getElementById('des');
    	 var popup = document.getElementById('popup');
         site.style.display = 'none';
    	 popup.style.display = 'block';     
       }
    }
    and heres the form
    HTML Code:
    <form action="" method="post" enctype="multipart/form-data" name="form1" class="style2">
    	<table border="0" cellpadding="0" cellspacing="5">
    	<tr><td>
    	Project Type:
    	</td><td>
    	<select id="port_type" name="port_type" onchange="show_hide_pop()">
    	<option <?php if($isWeb == 'true'){ echo 'selected="selected"'; } ?> id="web">Website</option>
    	<option <?php if($isFlash == 'true'){ echo 'selected="selected"'; } ?> id="flash">Flash</option>
    	<option id="image">Image</option>
    	</select>
    	<script>
    	show_hide_pop();
    	</script>
    	</td></tr>
    	<tr><td>
    	Project Name:
    	</td><td>
    	<input type="text" id="name" name="name" size="35" value="<?=$name?>" />
    	</td></tr>
    	<tr><td>
    	Pop-Up URL:
    	</td><td>
    	<input type="text" name="des" id="des" size="35" value="<?=$popup?>" />
    	</td></tr>
    	<tr><td>
    	Pop-Up File:
    	</td><td>
    	<input name="popup" type="file" id="popup" size="20" value="<?=$popup?>">
    	</td></tr>
    	<tr><td>
    	Image:
    	</td><td>
    	<input name="product_image_sm" type="file" id="product_image_sm" size="20" value="<?=$image?>">
    	</td></tr></table>
    	<?php
    	if($_GET['project_id']){
    		echo '<input type="submit" name="Update"  id="Update" value="Update"/>';
    	}else{
    		echo '<input type="submit" name="Create"  id="Create" value="Create"/>';
    	}
    	?>
    	<br />
    </form>
    but the line :
    var site = document.getElementById('des');
    is coming up as null instead of an pbject but if try it with the form name instead
    var site = document.getElementById('form1');
    it sees my form as an object....does anyone know what im doing wrong??

    thanks
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  4. #4
    .* draziW tnioPetiS *. bronze trophy
    Join Date
    Jun 2004
    Location
    "Then I figure the most good good guy will win."
    Posts
    1,666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    HTML Code:
    <form action="" method="post" enctype="multipart/form-data" name="form1" class="style2">
    I think you need to give the form an ID also... like so:

    HTML Code:
    <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" class="style2">
    Unfortunately I do not have time atm to test your code. Could be other/another problem... but maybe you already got it figured out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •