Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i put the value of a javascript variable into a form text value

    Hi i have a form page as follows

    <script language="JavaScript" TYPE="text/javascript">
    <!--

    var catnoval = 'test';

    //-->
    </script>

    <form action="##" method="post" name="amendform" id="amendform">

    <input type="Text" name="packcode" class="FormFieldSelect165px" value="<script language="JavaScript" TYPE="text/javascript">docuemt.writeln(catnoval );</script>">

    </form>


    When i want to view the form i get the whole '="<script language="JavaScript" TYPE="text/javascript">docuemt.writeln(catnoval );</script>' beeing displayed and not the actual value of the javascript variable! i.e 'test'

    Can anyone help me on how i can display this javascript variable inside the value attribute of the form's text element?

    Any help appreciated
    Thanks
    Zubair

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <script type="text/javascript">
    var myVar='test value';

    function initPage()
    { document.getElementById('myInput').value=myVar;
    return;
    }
    </script>
    ...
    <body onload="initPage()" ...


    <input id="myInput" name="myInput" type="text" value="" />


    Out of curiosity, where did you get your code???
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    var catnoval = 'test';
    
    function init()
    {
        document.forms['amendform'].elements['packcode'].value = catnoval;
    }
    
    </script>
    </head>
    
    <body onload="init();">
    
    <form action="##" method="post" name="amendform" id="amendform">
    
    <input type="Text" name="packcode" class="FormFieldSelect165px" value=""> 
    
    </form>
    
    </body>
    </html>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    beat you this time, beetle
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    *waves fist*

    <grandpa simpson>
    Darn you! Ahhhhh!
    </grandpa simpson>

    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    LoL - usually it's the defeated one that acknowledges the victor and not the other way around - ie "Bleh! you beat me to it, ..."
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you kidding, I practically work for Vladdy, the slave driver.



    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ROFLMAO, I thought that was another way round...
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •