Need help passing a value from an HTML form.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 2inshix
    New Member
    • May 2010
    • 11

    Need help passing a value from an HTML form.

    I have this code which imports a file depending on user's selection (3 radio buttons romaji, hiragana,kanji)
    The way it is now, checkImport() returns the last option (from handlers) no matter which button is selected. What changes Do I have to do the Javascript to activate the 3 selections? Any help will be greatly appreciated. Cheers!
    Code:
        whichlang = "English"
        def checkImport():
            if UserLogin.whichlang == "Hiragana":         sys.path.append(os.path.join(config.APP_ROOT_DIR, 'srcHiragana'))
                return __import__('conjugateNew')
            elif UserLogin.whichlang == "Kanji":            sys.path.append(os.path.join(config.APP_ROOT_DIR, 'srcKanji'))
                return __import__('conjugateNew')
            elif UserLogin.whichlang == "Romaji":            sys.path.append(os.path.join(config.APP_ROOT_DIR, 'srcRomaji'))
                return __import__('conjugateNew')
            else :#whichlang == "English":           sys.path.append(os.path.join(config.APP_ROOT_DIR, 'handlers'))
                return __import__('conjugateNew')
    Html code
    Code:
        <div id="Layer-5" class="_text editable"  >
            <input type="radio" name="langgroup" value="Romaji"checked> Romaji
            <input type="radio" name="langgroup" value="Hiragana" checked> Hiragana
            <input type="radio" name="langgroup" value="Kanji"checked> Kanji
        </div>
    Javascrip code
    Code:
    <script>
    $(document).ready(function() {
        var langgroup = "English"
        $("input[name='langgroup']").live("change", function() {
          //alert($(this).val());
          langgroup = $(this).val();
        });
     	$('#play').click( load_alerts );
    	function load_alerts()	{
    		var url = "/trial";
            data = {"whichlang":langgroup};
            $.post( url, data, post_ack_handler );	}
    
    	function post_ack_handler(data, textStatus, xmlObj){
            $("div#trial").html(data);
            if (textStatus == "error")
                $('#showerror').html(xmlObj.responseText);	}    
    });
    </script>
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    2inshix,

    It looks like you're starting in an incorrect state - all three radio buttons are set as "checked" in your HTML.

    Try setting only one to "checked" to start with.

    Luck!
    Oralloy

    Comment

    • 2inshix
      New Member
      • May 2010
      • 11

      #3
      Hello, Oralloy,
      Yes, you're s right! That was very silly of me wasn't it! (laughs)
      That problem is solved, but there's a new issue. Once the selection is made, that selection remains persistant; meaning it won't allow a new button selection, even after a page refresh. Can you think of a quick fix just from what you see above?

      Any suggestions would be greatly appreciated.

      Cheers

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        I think your problem lies in the JavaScript bit
        Code:
        $("input[name='langgroup']").live("change", function() { 
              //alert($(this).val()); 
              langgroup = $(this).val(); 
            });
        You need to verify that the correct value is being used in the assignment.

        Cheers!
        Oralloy

        Comment

        Working...