www.webdeveloper.com
Results 1 to 5 of 5

Thread: javascript rogram not working

  1. #1
    Join Date
    Jan 2012
    Posts
    24

    javascript rogram not working

    Hello
    I am trying to send some values in combobox2 depending on one value selected in combobox1. Both are in php. Following is the code for combobox1 -

    Code:
    <td><div id="Gen_Core">
       <?php  
       $sql="SELECT t.Main_CoNo, t.Main_CoName FROM Main_Course t WHERE t.Modl_No ='2' and t.Main_CoName NOT IN (SELECT t1.Course_Name from Course t1 where t.Modl_No = t1.Module_ID and Student_ID='$Stud_ID')";
       $result=mysql_query($sql);
       $options="";
       while (@$row=mysql_fetch_array($result)) 
    {    $id=$row["Main_CoNo"];    $name=$row["Main_CoName"];    $options.="<OPTION VALUE=\"$id\">".$name.'</option>';
    }  
       ?><select size="4" style="width:100px; font-size: 10px;" name="classes[]" id="class_list" onClick="return validateForm()"><?=$options?></select></div></td>
    Here is Javascript program -
    <script type="text/javascript">
    function validateForm()
    {
    var gen=document.forms["select"]["classes"].value;
    alert("hi");

    }
    </script>

    If I select one value from this combobox1, I want to send that value to java script program which is not working...It is not going to Javascript program at all.. I tried couple of things like onClick, onSubmit in form, in select etc. But it seems nothing is working...
    What I want is - If one option is selected from combobox1, then javascript program should recognize it and send values for combobox2. How will I do it? Really confused.....

  2. #2
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Is jQuery available to you? It will simplify this task greatly. In plain javascript, try something like:
    Code:
    var selected = document.getElementById('SomeID').value;
    if(selected == 'something'){
    //do stuff
    }
    and to trigger, try using 'onchange'
    Last edited by NoEffinWay; 04-04-2012 at 12:24 PM. Reason: LOL 'tigger'

  3. #3
    Join Date
    Jan 2012
    Posts
    24
    Thanks for replying.... It worked....

  4. #4
    Join Date
    Jan 2012
    Posts
    24
    Does anyone know how to assign javascript value to combobox in html? I am trying like this - form.combo_gen.value = document.selected.sem1.value;
    sem1 is the javascript variable and I am trying to pass it to html combobox.....

  5. #5
    Join Date
    Jan 2012
    Posts
    24
    hey NoEffinWay,
    Do u know how to assign javascript value to combobox in html? I am trying like this - form.combo_gen.value = document.selected.sem1.value;
    sem1 is the javascript variable and I am trying to pass it to html combobox.....

Thread Information

Users Browsing this Thread

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

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