www.webdeveloper.com
Results 1 to 1 of 1

Thread: Please help to solve this (javascript) problem.

Threaded View

  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Please help to solve this (javascript) problem.

    i am new to web programming. i need to create a dynamic form with set of dynamic form elements. The problem is when i pass the value from text box to list box. all the values are passed to first list box.
    here i include my code for your view. please check and give any idea.
    page1:field1.php
    Enter No
    Code:
    <form name="test" method="post" action="dynamic.php">
      <label>
      <input type="text" name="no" id="no">
      </label>
      <br><br>
      <input type="submit" name="submit" value="submit">
    </form>
    page2:dynamic.php
    Code:
    <!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>
    <title> Dynamic List building </title>
    
    <script type='text/javascript'>
    function getXMLHTTP() { 
    		var xmlhttp=false;	
    		try{
    			xmlhttp=new XMLHttpRequest();
    		}
    		catch(e)	{		
    			try{			
    				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(e){
    				try{
    				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    				}
    				catch(e1){
    					xmlhttp=false;
    				}
    			}
    		}
    		 	
    		return xmlhttp;
    	}
    	
          //----------------------------------------------------------------
          
          </script>
    <script type='text/javascript'>
      function show_choice( sel, partnerID ) {
      }
      function show(id) {
      
          	  var ele = document.getElementById( id )
        if ( ele ) {
          ele.style.display = 'inline'
        } else {
          alert( 'Specified element not found: id="' + id + '"' )
        }
      }
      function Add( val ) {
        var sel = document.getElementById( 'SubCat' )
        sel.options[ sel.options.length ] = new Option( val )
        document.getElementById( 'here' )
      }
      
      function removeAllOptions(selectbox)
    {
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
    selectbox.remove(i);
    }
    }
    function removeOptions(selectbox)
    {
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
    if(selectbox.options[i].selected)
    selectbox.remove(i);
    
    
    }
    }
    function GetValue()
    {
    var sat=new Array();
    var new1="";
    var sa=document.drop_list.SubCat.length;
    for(i=0;i<sa;i++)
    {
    sat[i]=document.drop_list.SubCat[i].value;
    alert(sat[i]);
    new1 +=sat[i]+"$";
        }
       
      var strURL="yourpage.php?type="+new1;
      		var req = getXMLHTTP();
    		alert(new1);
    		if (req) {
    			
    			req.onreadystatechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						//document.getElementById('statediv').innerHTML=req.responseText;	
    						
    						}
    						 else 
    						 {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}
    			alert(strURL);			
    			req.open("GET", strURL, true);
    			req.send(strURL);
    		}		
    	
    
    	}
     
    </script>
    <?
    echo "hi";
    echo $form=$_POST['no'];
    print("<form action=\"value.php\" method=\"post\">");
    for($i=0;$i<$form;$i++)
    {
    print("<input type=\"text\" name=\"no[]\" /><br>
    Enter: <input type='text' id='here' onchange='Add(this.value)'><br>
    <input type='button' value='AddCity' onClick='show(\"here\")'><br>
    <input type='button'  onClick=\"removeOptions(SubCat)\" value='Remove Selected'><br>
    <input type='button'  onClick=\"removeAllOptions(SubCat)\" value='Remove All'><br>
    <select  id=\"SubCat\" size=\"10\" >
        <option name=\"Ada\"      id=\"Ada\"       value=\"Ada\">-----------------------</option>
        
      </select>
      <input type=\"button\" name=\"add\" value=\"add\" onClick=\"GetValue()\" >"
    );
    }
    print("<input type=\"button\" value=\"submit\"/> </form>");
    ?>
    Last edited by Kor; 08-28-2009 at 05:17 AM. Reason: wrap the code [code][/code]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles