embeding javascript in anchor tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    embeding javascript in anchor tag

    hi i am trying to use javascript in the anchor tag within the href attribute but it is not picking the value instead it is posting the javascript as a text when i click that link here are the combination i have already tried.
    Code:
    <a href="index.php?nxId=document.getElementById('questions').options[document.getElementById('questions').selectedIndex].value"></a>
    
    <a href="index.php?nxId=<script type='text/javascript'>document.getElementById('questions').options[document.getElementById('questions').selectedIndex].value</script>"></a>
    
    <a href="index.php?nxId=<?php echo '<script type='text/javascript'>document.getElementById('questions').options[document.getElementById('questions').selectedIndex].value</script> ?>"></a>
    any help in this regard
    Omer Aslam
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi Omer,
    Why cant you have a function and set the values through that, instead of setting in the href itself?

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      i already did it via ajax but myt senior said that the application is to be used with in the intranet not online and it is more possible that such applications will fail due to not having javascript enabled on their machine so everything should be done via php
      regards,
      Omer Aslam

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        neither of your lines is correct. the first one is not recognised as JavaScript and the latter are violating the HTML syntax (thus it is also not executed).

        cou can use PHP only after the form submit and it will not react upon immediate changes. if you use AJAX to submit those changes to the server, you can as well use standard JavaScript to do the same and just change the href.

        the embedding works only, if you have an event handler defined.

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          yeah as i told i had already done it through AJAX it woz a piece of cake but now its irritating me :(

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by omerbutt
            i already did it via ajax but myt senior said that the application is to be used with in the intranet not online and it is more possible that such applications will fail due to not having javascript enabled on their machine so everything should be done via php
            You do realise:
            1. If you have JavaScript disabled, none of these attempts will work even if you had the correct syntax,
            2. On the intranet, you have more control over the settings. You can ensure that everyone has JavaScript enabled.

            If you want to do everything via PHP, use a form and submit.

            Comment

            Working...