0

I am unable to convert jquery code into javascript code. I need iteration in javascript. Can please suggest me, how to solve this problem. And also add the html code. Can you check it once.Thank you in advance.

i have small dought in above code. I tried above code in my local. I want disply the one value. it's working fine. I want display the one more value, in that case actually it displays the two values but it displayed three values. Can please suggest me how to solve the issue.Thanks you. For example :- 2 [ first enter the value] => it displayed 2 :- 7 [ enter one more vallue] => actually is displyed 2,7 but it displyed the value is 2,3,7

This is the html code :-

<?php
$form_fields = array(           
        'acad_year' => array('label' => '', 'label_html' => '', 'after_html' => '', 'required' => FALSE,  'class' => '', 'id' =>'year_select', 'view' => 'input/pulldown','value' => ssp_get_regform_value($user, $type, $formreturn, 'acad_year')),

        'acad_campus' => array('label' => '', 'label_html' => '', 'after_html' => '', 'required' => FALSE,  'class' => '', 'id' =>'campus_select', 'view' => 'input/pulldown','value' => ''),

        'acad_course' => array('label' => '', 'label_html' => '', 'after_html' => '', 'required' => FALSE,  'class' => '', 'id' =>'course_select', 'view' => 'input/pulldown','value' => ''),

        'acad_specialization' => array('label' => '', 'label_html' => '', 'after_html' => '', 'required' => FALSE,  'class' => '', 'id' =>'specialization_select', 'view' => 'input/pulldown','value' => ''),

        'submit' => array('label' => '', 'label_html' => '', 'after_html' => '', 'required' => FALSE,  'class' => '', 'id' =>'profile_edit_submit_stg_1', 'view' => 'input/submit','value' => 'Add a course'), 

    );
    echo "<br>Please select one of the courses below<span class='cnfrm_warning'>*</span><br>";
    //var_export($form_fields);
    ssp_render_regform_array($form_fields);
    ?>
    <div id="acad_debug_pane"></div>
    <div id="acad_result_pane"></div>
    <div id="result_form_div">
    <p><b>Currently selected courses</b></p>

    <form  method="post" id="result_holder_ssp" onSubmit="return acad_result_checkform();" name="acad_final_submit">    
    <input type ="hidden" id="last_course_count" value = "">
    <input type ="submit" name="acad_conditional_submit_" class="regform-submit" id="acad_conditional_submit_id" value="Submit Changes">    
  </div>

var course_map =  new Array(0);
 $("form#result_holder_ssp :input").each(function(){
    var input = $(this);      
      if(input.hasClass('ssp_selected_course') || input.hasClass('ssp_selected_course_sugg')){

          console.log(input.attr("name"));
          course_map.push(input.val());

        }

    });
1

1 Answer 1

1

You could try with something like this:

-- EDIT --

    var form = document.getElementById("result_holder_ssp")
    inputs = form.getElementsByTagName('input');
    for (index = 0; index < inputs.length; ++index) {
         // deal with inputs[index] element.
         if(inputs[index].className.indexOf('ssp_selected_course') > -1 || inputs[index].className.indexOf('ssp_selected_course_sugg') > -1){

              console.log(inputs[index].getAttribute("name"));
              course_map.push(inputs[index].value);

        }
    }

I did a typo with the attribute "className" i originally typed "classname" and is case sensitive, also a problem with the spaces in the className comparisson.

Sign up to request clarification or add additional context in comments.

11 Comments

Hi cralfaro, Thank you very much for giving reply to me. I tried above code in my local. It is not working. Can you please suggest me sir.
could you paste the html code of your page in your question also? so i can try why is not working, thanks
@sree could you try it now? Thanks!
Hi Cralfaro, Just Now i updated my question. Can you please check it once. Thank you very much sir.
@sree check my response, but i see your form tag is not closed, this could generate errors. tell me if the code is working now.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.