SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    only run javascript if radiobutton is "yes"?

    hi, i've got a javascript that checks an input field in a form if that field is filled correctly, but now i only want to do that check if a radiobutton above in the field stands in "yes", is there a way to do that?
    cheers!
    /Måns

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if (document.yourForm.yourRadioButton.value == "yes"){
    checkInputField()
    }

  3. #3
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks mate! worked like a charm!
    /Måns

  4. #4
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    new problem

    came back to work now on monday, and it didnt work anymore...

    it seems like since i have two radiobuttons, both with the same name (since im passing their value as a variable), the script gets confused and dont know which button to check... or something, im just guessing since javascripting really isnt my area... anyways, here's the code, anybody who knows how to fix this problem?

    Code:
    Block description done:<br>
    <?php if ("yes" == $row["block_description"]) { ?>
    
    
    Yes: <INPUT TYPE="RADIO" NAME="block_description" VALUE="yes" CHECKED> No: <INPUT TYPE="RADIO" NAME="block_description" VALUE="no">
    
    <? } else { ?>
    
    Yes: <INPUT TYPE="RADIO" NAME="block_description" VALUE="yes"> No: <INPUT TYPE="RADIO" NAME="block_description" VALUE="no" CHECKED>
    
    <? } ?>
    
    <script language="JavaScript">
     <!--
     function isValidDate4() {
      if (document.update.block_description.value == "yes") { 
    var dateStr = document.update.block_description_date.value;
    
    blah blah code code
    
    }
    }
     -->
      </script>
    	
    <br>If yes, then: Block description date (YYYY-MM-DD):<br>
    <INPUT TYPE="TEXT" NAME="block_description_date" VALUE="<?php echo($row["block_description_date"]); ?>" SIZE="40" onBlur="isValidDate4()"><br>

    anybody?

  5. #5
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried to replace the radiobuttons with a dropdown, like this but that doesnt seem to work either...

    Code:
     
    Block description done:<br>
    <? if ( yes == $row["block_description"] ) { ?>
    
    <SELECT name="block_description">
    <option selected>yes
    <option>no
    </SELECT><br>
    
    <? } else { ?>
    
    <SELECT name="block_description">
    <option>yes
    <option selected>no
    </SELECT><br>
    
    <?
    }
     ?>


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
  •